How to get complete current url for Cakephp How to get complete current url for Cakephp php php

How to get complete current url for Cakephp


You can do either

From a view file:

<?php echo $this->request->here() ?>">

Which will give you the absolute url from the hostname i.e. /controller/action/params

Or

<?php echo Router::url(null, true) ?> 

which should give you the full url with the hostname.


I prefer this, because if I don't mention "request" word, my IDE gives warning.

<?php echo $this->request->here; ?>

API Document:class-CakeRequest


Edit:To clarify all options

Current URL: http://example.com/en/controller/action/?query=12// Router::url(null, true)http://example.com/en/controller/action/// Router::url(null, false)/en/controller/action/// $this->request->here/en/controller/action/// $this->request->here()/en/controller/action/?query=12// $this->request->here(false)/en/controller/action/?query=12// $this->request->urlen/controller/action// $_SERVER["REQUEST_URI"]/en/controller/action/?query=12// strtok($_SERVER["REQUEST_URI"],'?');/en/controller/action/


<?php echo $_SERVER[ 'REQUEST_URI' ]; ?>

EDIT: or,

<?php echo $this->Html->url( null, true ); ?>