Cakephp: how to get full url to the current request/page

4.9k views Asked by At

Some body please help me how to get full url i.e with scheme and host of the current page in the view. I tried the following, but didnt return the expected results

$this->request->here; // returns uri plus base path. no host & scheme
$this->request->here(true); // same problem
2

There are 2 answers

0
Jacek B Budzynski On BEST ANSWER
<?= $this->Url->build(null, true); ?>

Here you are more info:

http://book.cakephp.org/3.0/en/views/helpers/url.html#generating-urls

4
Akshay Sharma On

You can get domain,scheme,path like this :

use Cake\Routing\Router;
$domain = parse_url(Router::url('/', true));
pr($domain);

OR

use Cake\Routing\Router;
$url = Router::url(null, true);

Controller,action path can be get by :

$this->request->here