2

is this possible? I'm using one controller for (almost) the same functionality for two different pages. Is it possible to distinguish the source of the request in order to vary functionality?

Note: This controller is used to process ajax calls.

2 Answers 2

5

You can get the current url with Mage::helper('core/url')->getCurrentUrl().

As @mbalparda said, the request object could be better for your purposes.

Try these methods:

$request = $this->getRequest();

$request->getRouteName();
$request->getControllerName();
$request->getActionName()

With this you can get your route, controller and action without parsing an URL.

3
  • Mage::helper('core/url')->getCurrentUrl() returns the URL of the controller that is used to process these requests. Commented Feb 5, 2015 at 15:18
  • 1
    Sorry, didn't quite understand your question the first time. Looking at this question I think that Mage::app()->getRequest()->getServer('HTTP_REFERER') could be useful.
    – Isaias
    Commented Feb 5, 2015 at 15:23
  • Is this method can return url with query string or note for ex "www.xyz.com/products?p=1" like this? Commented Nov 16, 2018 at 9:02
2

Use $this->getRequest() to see how can you differentiate the requests. Inside that var you will have some more details about the request. Dump it and see what is inside and act consequently with the info.

2
  • The requests set to this controller from the two different pages (cart and checkout) are indistinguishable. Commented Feb 5, 2015 at 15:20
  • 2
    Dump the var and you will see more things than the request path, for example the referrer.
    – mbalparda
    Commented Feb 5, 2015 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.