I am using Magento I need to prevent ratings in the frontend from saving after the reviews has been saved. So I have used the <reveiw_save_after> event in order to achieve it. But I am unable to stop the controller action from happening after the save event. Here is my code:




     class MyModule_Rating_Model_Observer
        function preventAddRatings(Varien_Event_Observer $observer)
            $app = Mage::app();
            $request = $app->getRequest();

$app->getFrontController()->getResponse()->setRedirect($request->getBaseUrl() . $request->getPathInfo());

The observer is calling but the controller action is still executing. Is this the correct way to prevent the controller action?.



I tried using the below code but I am unable to get the controller action from the observer object.

$controller = $observer->getControllerAction(); $controller->getRequest()->setDispatched(true); $controller->setFlag( '', Mage_Core_Controller_Front_Action::FLAG_NO_DISPATCH, true );

1 Answer 1


After setting the redirect you need to call the response object's sendResponse() method and terminate execution.

Note that your observer needs to be configured under the frontend event area, as it would not be appropriate for this redirect to occur in the admin.

  • I added the observer in the <frontend> tag and the code is calling after the review save event, but I tried adding the $request->sendResponse() after the setRedirect() which you mentioned, but no luck, the rest of the controller code gets executed. I tried putting exit(), the reviews are not saving.
    – Dinesh
    Jul 12, 2013 at 12:24
  • In most cases return; is good enough. Don't call exit or die - makes testing difficult.
    – philwinkle
    Jul 12, 2013 at 17:52
  • 1
    return will not work in this case, because the remaining execution scope may set a different redirect header on the response object before it is sent by the Front Controller.
    – benmarks
    Jul 12, 2013 at 21:08

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.