cakephp3 Class DateTime not found

Alessandro Minoccheri picture Alessandro Minoccheri · Apr 7, 2015 · Viewed 8.3k times · Source

I'm trying to convert my cakephp plugin from 2.X to 3.

I have a little problem inside my component plugin at this line:

$dStart = new DateTime($now); //$now = date('Y-m-d H:i:s');

return me this error:

Error: Class 'CurrencyConverter\Controller\Component\DateTime' not found 

Seems that it search DateTime inside my plugin directory. How can I solve it?

Thanks

Answer

marian0 picture marian0 · Apr 7, 2015

Try:

$dStart = new \DateTime($now);

because CakePHP 3.0 using namespaces and if you not add a root namespace it will be looking for class under current namespace.