Get Current Url in Cakephp


Get Current Url in Cakephp : $this->here is used to get the current url in cakephp. it will give you the absolute current url. $this->request->here is also used to get current url. Here we are going to explain the method to get current url in cakephp on controller, view or model file.


Get Current Url in Cakephp

Syntax to get current url is as –

Absolute Current Url

Get Absolute Current Url in cakephp

$currentUrl = $this->here;
echo $currentUrl;

Will give you absolute current url such as “/users/profile/view”

Full Current Url

Get Full Current Url in cakephp

$currentUrl = Router::url( $this->here, true );
echo $currentUrl;

Will give you full current url such as “www.example.com/users/profile/view”

You can also use the below syntax to get current url –

Absolute Current Url in cakephp

$currentUrl = $this->request->here;
echo $currentUrl;

Will give you absolute current url such as “/users/profile/view”


Advertisements

Add Comment

📖 Read More