Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get $this->webroot work in CakePHP 3.0

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!

like image 748
bluesclues9 Avatar asked Mar 23 '15 17:03

bluesclues9


2 Answers

You need to use this:

href="<?php echo $this->request->webroot . 'intro/services/1'; ?>

This will work with cakephp 3.0

like image 156
Vivek Avatar answered Nov 18 '22 07:11

Vivek


In cakephp 4.x you need to use this:

href="<?php echo $this->Url->webroot.'/intro/services/1'; ?>
like image 39
sanjay verma Avatar answered Nov 18 '22 08:11

sanjay verma