Cakephp 3.0 | Methods to get base and application url

|
| By Webner

In cakephp we do not need to set hard coded relative paths.There are methods by calling which we can build the url dynamically.

use Cake\Routing\Router;
To get the base url use
Router::fullBaseUrl(); => http://localhost //Output

To get the Application Url
Router::url(); =>/CakeApp/ //Output

To build complete URL of controller and method called:
$this->Url->build([‘controller’=>Users,’action’=>’index’])

//output is
/users/index

Leave a Reply

Your email address will not be published. Required fields are marked *