In this second blog post from our Magento Custom Development series, we'll discuss the config.xml file to help you use the Cost Report Module.
Config.xml
The config.xml file only has a few sections:
Modules
Like all other extensions, the modules section defines the version.
<modules>
<Eyemagine_CostReport>
<version>0.1.0</version>
</Eyemagine_CostReport>
</modules>
Admin
Because Reports are only represented within the admin view, it is important to notify Magento to look inside your extension before the Adminhtml extension for any classes.
<admin>
<routers>
<adminhtml>
<args>
<modules>
<costreport before="Mage_Adminhtml">Eyemagine_CostReport_Adminhtml</costreport>
</modules>
</args>
</adminhtml>
</routers>
</admin>
The line with ‘before=“Mage_Adminhtml”’ instructs Magento that your extension is adding controllers to the Magento Admin area, as well as providing Magento with the path to the custom controllers, which in this case is Eyemagine_CostReport_Adminhtml.
You might see some extensions have an admin configuration similar to the frontend method where you declare the “frontName”. While using “frontName” is correct for frontend controllers, it goes against “magento best practices” to route an admin controller in this way.
The reason for this difference is that custom Adminhtml controllers are either overriding (subclassing) Magento default controllers or adding new functionality. If you are creating new functionality, make sure your controller paths are unique. Because the extension is routed before Mage_Adminhtml, your custom controller will be called and appear to be a native adminhtml controller.
The Cost Report will be creating new functionality, and therefore the router path needs to be unique.
Global
The global section is used to define the class prefix for each of the class types this extension supports. Global areas can also be used to rewrite existing Magento classes, but that functionality is not part of this extension.
<global>
<models>
<costreport>
<class>Eyemagine_CostReport_Model</class>
<resourceModel>costreport_resource</resourceModel>
</costreport>
<costreport_resource>
<class>Eyemagine_CostReport_Model_Resource</class>
</costreport_resource>
</models>
<blocks>
<costreport>
<class>Eyemagine_CostReport_Block</class>
</costreport>
</blocks>
<helpers>
<costreport>
<class>Eyemagine_CostReport_Helper</class>
</costreport>
</helpers>
</global>
The models area above defines the minimum required to declare the models required for this extension. Magento has been transitioning from the Mysql4 model type to the more generic resource type, so you might see a few references to Mysql4 in other report tutorials.
Magento handles this transition by including the Mysql4 models, but declares them as depreciated in the config.xml and changes the class inheritance name so that they extend the appropriate Resource model instead. By declaring the Mysql4 extends Resource models, it provides backwards compatibility with Magento CE 1.5 and prior without causing code duplication issues.
Here is one example: Mage_Reports_Model_Mysql4_Order_Collection extends Mage_Reports_Model_Resource_Order_Collection.
It is also possible that the extension will use aggregated tables to summarize the data into a format that is more efficient to render the report data. In that case, you would also declare any database entities to be added to the extension within the <models> resource area.
Need further assistance? Contact one of our Magento experts today for a free consultation. Our team is standing by and happy to help with any of your Magento needs!