Method in Controller to get current url

13,379

To get the current relative URL in either your view or your controller, you can do this:

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

If you want to get the full URL in your controller, including domain, do this:

<?php echo Router::url( $this->here, true ); ?>

You won't be able to pass anything from your view back to your controller - that's not how MVC works.

Almost the exact same question is asked here: How to get complete current url for Cakephp

Share:
13,379
Duc Anh
Author by

Duc Anh

Updated on June 04, 2022

Comments

  • Duc Anh
    Duc Anh almost 2 years

    As the title, I want to ask is there a method in Controller to get current url in CakePHP ?

    Or I have to do this in View then pass it ass parameter to Controller ?

    Please help me out :)