2

I am upgrading my cakephp version from 2.6.7 to 3.3.4. The following code was properly working to refer the home url:

<?php echo Router::url('/', true); ?>

But this not working in cakephp 3.3.4 and it shows the following error message:

Error: Class 'Router' not found 

Which I missed? Thanks in advance.

ndm
  • 59,784
  • 9
  • 71
  • 110
Abdus Sattar Bhuiyan
  • 3,016
  • 4
  • 38
  • 72

1 Answers1

8

You need to make yourself comfortable with PHP namespaces. The Router class lives in the Cake\Routing namespace, hence you have to use either:

\Cake\Routing\Router::url()

or import the class:

use Cake\Routing\Router;

That being said, in your views you may want to use the Url helper instead (as mentioned by Jacek B Budzynski in the comments), in order to avoid the hard dependency on the Router class:

$this->Url->build('/', true)

See also

ndm
  • 59,784
  • 9
  • 71
  • 110