In app/code/core/Mage/Customer/conrtrollers/AccountController.php there is

            array('account_controller' => $this, 'customer' => $customer)

How this event code i.e customer_register_success is fired in magento when dispatchEvent is called.


1 Answer 1


If you look into the function dispatchEvent in the class Mage_Core_Model_App you will see that the code works as follows:

NOTE: for this example I will use the event controller_front_init_routers simply because this happens a lot and is easier to step through the code with

Firstly what happens is that all the observers set-up in the config are loaded into an array of the format:

$observers['observer_name'] = array(
    'type'  => 'observer_type,
    'model' => 'observer_model',
    'method'=> 'method_to_call',
    'args'  => 'arguments_array',

This matches the way you define an observer via xml as follows.


For our example the array looks as follows.

array(1) {
  array(4) {
    string(0) ""
    string(26) "Mage_Cms_Controller_Router"
    string(21) "initControllerRouters"
    array(0) {

Then what happens is the dispatchEvent function checks to see if the event we want to dispatch has something listening to it. If it does not then it wont continue any further but when it does it continues to build an event object and observer object.

It then loops through all the stored event information, sets the data arguments and calls the desired method on the desired object. Note that by default the model is loaded as a singleton.

foreach ($events[$eventName]['observers'] as $obsName=>$obs) {
    Varien_Profiler::start('OBSERVER: '.$obsName);
    switch ($obs['type']) {
        case 'disabled':
        case 'object':
        case 'model':
            $method = $obs['method'];
            $object = Mage::getModel($obs['model']);
            $this->_callObserverMethod($object, $method, $observer);
            $method = $obs['method'];
            $object = Mage::getSingleton($obs['model']);
            $this->_callObserverMethod($object, $method, $observer);
    Varien_Profiler::stop('OBSERVER: '.$obsName);

One final thing that happens is that the _callObserverMethod function checks to see if the desired method exists and when it does not it throws an exception.

So for our example we will be using the model Mage_Cms_Controller_Router and the method initControllerRouters.


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.