Magento:config.xml文件中的“之前”选项有什么作用?

时间:2012-08-25 20:35:03

标签: magento

我添加了管理员控制器。 此代码的工作正确:

    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <mycompany_mymodule>Mycompany_Mymodule_Adminhtml</mycompany_mymodule >
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>

如果我在mycompany_mymodule之前添加=“Mage_Adminhtml”:

<mycompany_mymodule before="Mage_Adminhtml">Mycompany_Mymodule_Adminhtml</mycompany_mymodule >

然后它不起作用 - 得到404错误。

1。这个选项有什么作用?

我还查看了Alans的Storm文章:http://alanstorm.com/magento_admin_controllers 有例子:

<config>
    <!-- ... -->
    <admin>
        <routers>
            <the_name_of_this_element_is_not_important_it_should_be_unique>
                <use>admin</use>
                <args>
                    <module>Alanstormdotcom_Adminhelloworld</module>
                    <frontName>adminhelloworld</frontName>
                </args>
            </the_name_of_this_element_is_not_important_it_should_be_unique>
        </routers>
    </admin>
    <!-- ... -->        
</config>

2。这些定义有什么区别?

1 个答案:

答案 0 :(得分:3)

它解决了:

我找到了Mage_Core_Controller_Varien_Router_Standard类,其中定义了collectRoutes()方法。它解析“after”和“before”参数以对模块进行排序。

此方法从Mage_Core_Controller_Varien_Router_Admin调用(从init中的Mage_Core_Controller_Varien_Front方法开始)。

所以在我查看Mage_Core_Controller_Varien_Router_Standard中的匹配过程后。

Mage_Core_Controller_Varien_Router_Standard调配后,我理解了我的错。

  1. 我使用了索引控制器而不是MyModuleContoller

  2. Alan Storm在 admin 模块(即adminhtml)下定义了的控制器。当我使用第一个配置时 - 它完美无缺,因为我在 adminhtml 部分下定义了新模块。在Alan的配置中,我无法将我的模块添加到adminhtml。我可以覆盖它,但它不正确,因为adminhtml下的其他模块将被删除。

  3. 这是adminhtml

    下菜单的正确代码
        <admin>
            <routers>
                <adminhtml>
                    <args>
                        <modules>
                            <mycompany_mymodule after="Mage_Adminhtml">Mycompany_Mymodule_Adminhtml</mycompany_mymodule >
                        </modules>
                    </args>
                </adminhtml>
            </routers>
        </admin>
    

    Inchoo还描述了这个配置here

相关问题