Cakephp Get Base Url


Cakephp Get Base Url – You can get base url in cake php using the $this->webroot;. Here in this tutorial we are going to explain how you can get the base url in cakephp.


Cakephp Get Base Url Example

You can get base url using the following method –

Method 1

Using the $this->webroot; you can get the base url in cakephp.

Cakephp Get Base Url Example:

$baseUrl = $this->webroot; 

The above example will give you the base url.

Method 2

Using the $this->html->url(‘/’, true); you can also get the base url in cakephp.

Cakephp Get Base Url Example:

$baseUrl = $this->html->url('/', true);; 

The above example will also give you the base url. You can use any of the above.

More Examples

Let’s have look over more example and demo here.

Cakephp get base url in view

If you want base url in view you can use the following method described above-

Cakephp Get Base Url Example:

$baseUrl = $this->webroot;  

Cakephp get base url in Controller

If you want base url in controller you can use the following method –

Cakephp Base Url In Controller Example:

$baseUrl = Router::url('/', true); 

Advertisements

Add Comment