Posts tagged ‘Controllers’
Controllers
Controllers
Controllers are the starting point for all business logic inMagento. The line between what is considered business logic (rules that define a business’s methodology) and what is domain logic (instructions about a set of data) is blurry in Magento. Some people would consider checking for required and optional form fields as “business logic”, other peoplewould consider that “domain logic”. Most of the logic inMagento is done in the models.
Controllers extend a base class of Mage_Core_Controller_Varien_Action, which is a close copy of the Zend Framework class Zend_Controller_Action. The important methods of this class are:
• dispatch($action)
• preDispatch()
• postDispatch()
The rest of the methods are simply utility URLs to pass commands to other key parts of the system. The dispatch method starts all the business logic of the current request. The value of $action is determined from the URL and is generally “index” as a default. The dispatch method first calls preDispatch which triggers some events which you can listen for:
• controller_action_predispatch
• controller_action_predispatch_ModuleName
•controller_action_predispatch_ModuleName_ControllerName_ActionName
The dispatch method is called only if the preDispatch method does not mark the request as being dispatched already. The dispatch method calls the
particular action method in the desired co
ntroller instance
Recent Comments