简体   繁体   中英

Magento: What is the best way to extend Magento to add a class that is called on every page load

I am looking to create some new functionality to Magento. I am going to be looking to the url and grabbing a parameter. The issue is, this can be on any page. So I can't just extend a Catalog or Checkout Module.

I thought about extending the session classes but I wasn't sure it really fit. Basically I want to grab a parameter from the url and from there add some functionality if it is set or not. I don't think a class will get auto loaded unless it is instantiated somewhere else with a getModel method, am I wrong?

How can you add a module that doesn't have a url path for controller and what not, but doesn't fit extending one of the core modules?

I looked for a generic event but didn't really see one like before_page_load or something

Take a look at the event controller_action_predispatch in app/code/core/Mage/Core/Controller/Varien/Action.php . This event should get called on each dispatch and allow you to grab whatever parameters you need.

The event passes the controller as data, so you can do this:

function yourEvent( $event ) {
    $controller = $event->getController();
    // your processing here
}

Let me know if that doesn't fit the bill. Hope that helps!

Thanks, Joe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM