I had written a observer to trap product view page event and it is working fine.Now in that code i want to call a controller and pass the product id in it and render the custom view.phtml file, so how can i call that controller without changing my current browser url and render the view.phtml file on same url.

My Observer Code is Given Below

public function getProductView(Varien_Event_Observer $observer)
      $resp = $observer->getEvent()->getFront()->getAction()->getRequest();
      $requestUri = $resp->getRequestString();            
       if ($resp->getActionName() == 'noRoute'){
           $requestUri = $resp->getRequestString();
           $requestUri = ltrim($requestUri, '/');
           $this->db = Mage::getSingleton('core/resource')->getConnection('core_write');
           $sql = "SELECT * FROM core_url_rewrite WHERE request_path like '%".$requestUri."%'";
           $data = $this->db->fetchAll($sql);
           // header("Location: " . Mage::getBaseUrl() . "customproduct/prodId=".$data[0]['product_id'], 301);
           // exit;


           //Edit: action not passed in to this event; passed in generic generate_blocks event

1 Answer 1


You can do this by below code:



return true;

setDispatched(true/false) not sure..

  • Hi @Amit Bera thanks for your reply i have tried your solution $resp->setModuleName('customproduct') ->setControllerName('Index') ->setActionName('index')->setDispatched(true); but it is giving me white screen
    – RickyN73
    Commented Jun 26, 2015 at 6:49
  • update ..check now
    – Amit Bera
    Commented Jun 26, 2015 at 6:56
  • Hi @ Amit Bera, I tried this suggestion however Index controller is not called. When I go to browser and type {domain}/customproduct/index then index controller is getting called and I can see messge that has been echo'ed. However When we trap the event in observer, then from there index controller is not being called.
    – RickyN73
    Commented Jun 26, 2015 at 7:07
  • Part of the var_dump of $resp is protected '_dispatched' => boolean true protected '_module' => string 'customproduct' (length=13) protected '_moduleKey' => string 'module' (length=6) protected '_controller' => string 'index' (length=5) protected '_controllerKey' => string 'controller' (length=10) protected '_action' => string 'index' (length=5) protected '_actionKey' => string 'action' (length=6)
    – RickyN73
    Commented Jun 26, 2015 at 7:09
  • Hi @ Amit Bera do you have any idea how to do it
    – RickyN73
    Commented Jun 29, 2015 at 15:02

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.