Reputation: 121
I had this piece of code in my services.ctp
file which was working fine before in CakePHP 2.3.10.
href="<?php echo $this->webroot . 'intro/services/1'; ?>
I just copied this file into CakePHP 3.0.0 and it's no longer working and throwing the following error message
Error: C:\apache2\htdocs\myprojxxxx\webroot\Helper could not be found.
what's different with this $this->webroot
in CakePHP 3.0 ?
Please help!
Upvotes: 6
Views: 18806
Reputation: 11
Form me in cake 3.9 that work:
<img src="<?php echo $this->Url->build('/img/logo_app.png'); ?>" style="width:250px" />
Upvotes: 0
Reputation: 257
In cakephp 4.x you need to use this:
href="<?php echo $this->Url->webroot.'/intro/services/1'; ?>
Upvotes: 3
Reputation: 60503
This is not how you should have done it in the first place, as such "hard-coded" URLs are very inflexible in comparison to URL arrays, where it's the connected routes that define the generated URLs at a single point in your application, allowing you to easily make changes wihout having to apply modifications throughout the whole application.
That being said, the magic $webroot
property is gone (check the migration guide), its value can be retrieved directly via the View::$request
object.
You should however use Router::url()
, the UrlHelper
, or one of the HtmlHelper
methods instead:
\Cake\Routing\Router::url(['controller' => 'Intro', 'action' => 'services', 1])
$this->Url->build(['controller' => 'Intro', 'action' => 'services', 1])
$this->Html->link('Title', ['controller' => 'Intro', 'action' => 'services', 1])
See also
Upvotes: 1
Reputation: 223
You need to use this:
href="<?php echo $this->request->webroot . 'intro/services/1'; ?>
This will work with cakephp 3.0
Upvotes: 18