When we want to create our own event, we have to dispatch it with a custom name. In this recipe, we will learn how events are dispatched and what we can do with parameters that we will forward.
We will create our own event that is fired when a visitor opens the helloAction()
function of the Packt_Helloworld
module. In this recipe, we will build further on the Packt_Helloworld
module that is created in Chapter 4, Creating a Module, Chapter 6, Databases and Modules, and Chapter 7, Magento Backend. If you want, you can install the start files.
The following steps describe how we can dispatch our own event.
Open the
IndexController
of thePackt_Helloworld
module. In this controller, there is ahelloAction()
function where we will work to dispatch the event.To dispatch an event, the
Mage::dispatchEvent()
function is used. When we change the code of thehelloAction()
function to the following code, we will dispatch an event calledhelloworld_register_visit...