2
  1. I found many times this preDispatch function in Magento. I found this function mostly in controller file as a first function.
  2. Also sometimes in config.xml file.

Anyone, please help me what the purpose of this function in Magento and how to use it properly.

4

normally an url maps to an action in a controller.
This means that for each url one, and only one, method from a controller is executed.
preDispatch is not an action that you can map to an url. it is a method that gets called before executing an "action" method from a controller and it is called for all the actions in that controller.

  • if i want to fire an event in controller with Mage::dispatchEvent inside predispatch function then that event will fire for each and every action in that cotroller ?? – vijay rami May 31 '16 at 20:08
  • 1
    yes. Like I said, preDispatch is executed before every action in that controller. – Marius May 31 '16 at 20:44

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.