Question

Ok, so so far I have gotten /admin/helloworld to show up using my module's /etc/config.xml:

<config>
<module>
    <VMR_Reports>
        <version>1.0</version>
    </VMR_Reports>
</module>
<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <module1 before="Mage_Adminhtml">VMR_Reports_Adminhtml</module1> <!-- Namespace_Module_Subdirectory -->
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>
</config>

But I don't understand everything that is going on in that example.

1) I know I'm configuring a route, but why ? I'm pretty sure isn't a frontName since there is a method of doing this sort of thing where your admin section stuff for a module actually goes into the route, "/module/admin/..." which uses the following sort of XML:

<admin>
    <routers>
        <modulename_admin>
            <use>admin</use>
            <args>
                <module>NameSpace_Modulename</module>
                <frontName>modulename_admin</frontName>
            </args>
        </modulename_admin>
    </routers>
</admin>

So it seems more like here is a logical section. Can someone please explain what is going on in the first block of code a little? All I know is that the result of it is that I get /admin/controller/action to show up where I can specify _Adminhtml if I want to put stuff into Adminhtml subdirectories.

Was it helpful?

Solution

Well, I'll chime in, since I'm the guy from the Magento U video.

Nothing controller-related works without router configuration, which is the use, args/module, and args/frontName paths under admin/routers and frontend/routers. What these xpaths do is essentially connect the specified module's controllers directory to a frontName, allowing a request to be routed to an action in the controller.

Evaluation of the args/modules (note the s) path was introduced in Magento 1.3. It allows modules to add additional controller directories under extant frontNames. It's my contention that the Adminhtml module would not be the horrid aggregation that it currently is if this mechanism had existed from 1.0. Module controllers had to be under Mage/Adminhtml/controllers/ in order to use the admin frontName. For more information, see the 1.2 version of Mage_Core_Controller_Varien_Router_Standard::collectRoutes() and compare it to the 1.3+ version

The Admin router and Standard router both share the collectRoutes() method, meaning that what works for one works for the other. Therefore, there's generally nothing technically wrong with adding additional frontNames to the Admin router. However, there could be issues with admin cookie path and perhaps some funky stuff in the corner which would make me want to follow Magento's example, which is to use the args/modules mechanism to add directories under the Adminhtml module's frontName.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top