Create Observer in the Mage_core_model_app class for the run function

Asked

Viewed 95 times

1

When looking at the class app\code\core\Mage\Core\Model\App.php, we have the following function:

public function run($params)
    {
        $options = isset($params['options']) ? $params['options'] : array();
        $this->baseInit($options);
        Mage::register('application_params', $params);

        if ($this->_cache->processRequest()) {
            $this->getResponse()->sendResponse();
        } else {
            $this->_initModules();
            $this->loadAreaPart(Mage_Core_Model_App_Area::AREA_GLOBAL, Mage_Core_Model_App_Area::PART_EVENTS);

            if ($this->_config->isLocalConfigLoaded()) {
                $scopeCode = isset($params['scope_code']) ? $params['scope_code'] : '';
                $scopeType = isset($params['scope_type']) ? $params['scope_type'] : 'store';
                $this->_initCurrentStore($scopeCode, $scopeType);
                $this->_initRequest();
                Mage_Core_Model_Resource_Setup::applyAllDataUpdates();
            }

            $this->getFrontController()->dispatch();
        }
        return $this;
    }

To add a event/observer we use the following code:

<events>
  <EVENT_TO_HOOK>
    <observers>
      <module>
        <type>singleton</type>
        <class>company_module_model_observer</class>
        <method>methodToCall</method>
      </module>
    </observers>
  </EVENT_TO_HOOK>     
</events>

What event should we add to observe the function run class Mage_Core_Model_App?

1 answer

1


Unable to observe function run class Mage_Core_Model_App through an event.

The only event fired in this class was the application_clean_cache. Check out the full list on http://www.nicksays.co.uk/magento-events-cheat-sheet-1-8/

But the above listing is valid for version 1.8 - this above mentioned event no longer exists.

An event is triggered through the method dispatchEvent. For example:

Mage::dispatchEvent('application_clean_cache', array('tags' => $tags));

(source: http://freegento.com/doc/d8/d98/_app_8php-source.html#l01084)

In the function code run in app\code\core\Mage\Core\Model\App.php, posted on the question, we see that there is no call to Mage::dispatchEvent. This means that no event is triggered and therefore there is no event to be observed and captured there.

The alternative is extend the class and make a override of function.

Or (although not recommended) change the function code in Magento, adding the trigger of an event with dispatchEvent...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.