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.

  • You can try with Mage::app()->getRequest()->getControllerName(); – Rakesh Jesadiya Dec 16 '17 at 7:09
  • by this code i get the current page controller name not the previous page controller name. @RakeshJesadiya – pooja Dec 16 '17 at 7:14
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>"
  • ok i will try @abdul and let you know – pooja Dec 16 '17 at 9:41
  • @pooja wellcome :) – Abdul Dec 16 '17 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 – Vaibhav Ahalpara Dec 16 '17 at 10:02
  • hi @VaibhavAhalpara can you please post your code here. – pooja Dec 16 '17 at 10:05
  • @VaibhavAhalpara can u share you code ? – Abdul Dec 16 '17 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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