2

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 :)

Duc Anh
  • 581
  • 1
  • 9
  • 23

1 Answers1

11

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

Community
  • 1
  • 1
joshua.paling
  • 13,762
  • 4
  • 45
  • 60