Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get complete current url for Cakephp

Tags:

php

cakephp

How do you echo out current URL in Cake's view?

like image 348
Passionate Engineer Avatar asked Jul 26 '11 21:07

Passionate Engineer


People also ask

How can I get post data in CakePHP?

You can retrieve post data as Array. $post_data= $this->request->data; You can retrieve post data for particular key.


2 Answers

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.

like image 107
Abba Bryant Avatar answered Oct 15 '22 13:10

Abba Bryant


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->url en/controller/action  // $_SERVER["REQUEST_URI"] /en/controller/action/?query=12  // strtok($_SERVER["REQUEST_URI"],'?'); /en/controller/action/ 
like image 29
trante Avatar answered Oct 15 '22 13:10

trante