Webroot Within a View CakePHP

Webroot Within a View CakePHP

CakePHP4:

In CakePHP 4, you can use the following in a view to get the webroot of your software.

In a view or controller:

<?php echo $this->request->getAttribute("webroot"); ?>

One additional method to achieve nearly the same results is the Url Builder:

$this->Url->build('/path');

 

CakePHP3:

In a CakePHP3 Controller:

echo $this->request->webroot;

In a CakePHP3 View:

$this->request->getAttribute("webroot")

 

Share this Post