How do you echo out current URL in Cake's view?
You can retrieve post data as Array. $post_data= $this->request->data; You can retrieve post data for particular key.
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->url en/controller/action // $_SERVER["REQUEST_URI"] /en/controller/action/?query=12 // strtok($_SERVER["REQUEST_URI"],'?'); /en/controller/action/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With