2

I want to get the previous page controller action name from previous page URL in Magento 1.9.

I get the previous page url by this:

Mage::app()->getRequest()->getServer('HTTP_REFERER');

Now I tried to get the controller name from page url.

My question is "How to get the controller action name from page url?"

Thanks.

2
  • You can try with Mage::app()->getRequest()->getControllerName(); Commented Dec 16, 2017 at 7:09
  • by this code i get the current page controller name not the previous page controller name. @RakeshJesadiya
    – pooja
    Commented Dec 16, 2017 at 7:14

1 Answer 1

1

Try below code:

$baseUrl = Mage::getBaseUrl();
$refUrl = Mage::app()->getRequest()->getServer('HTTP_REFERER');
$refUrl = str_replace($baseUrl, '', $refUrl);
$previouController = explode("/", $refUrl);
echo $moduleName = (isset($previouController[0]) && $previouController[0]) ? $previouController[0] : '';
echo "<br>";
echo $controllerName = (isset($previouController[1]) && $previouController[1]) ? $previouController[1] : '';
echo "<br>";
echo $controllerAction = (isset($previouController[2]) && $previouController[2]) ? $previouController[2] : '';
echo "<br>"
10
  • ok i will try @abdul and let you know
    – pooja
    Commented Dec 16, 2017 at 9:41
  • @pooja wellcome :)
    – Abdul
    Commented Dec 16, 2017 at 9:54
  • I am also trying to previous page controller's name but did not get it. By using above code, I just get url key. But did not get controller name. How can i get controller name Commented Dec 16, 2017 at 10:02
  • hi @VaibhavAhalpara can you please post your code here.
    – pooja
    Commented Dec 16, 2017 at 10:05
  • @VaibhavAhalpara can u share you code ?
    – Abdul
    Commented Dec 16, 2017 at 10:05

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.