Magento Enterprise 控制器覆盖
我试图覆盖 Enterprise/CatalogEvent/controllers/Adminhtml/Catalog/EventController.php。
问题是config.xml。我如何遵循 Magento 的命名约定。 以下是config.xml文件
<admin>
<routers>
<adminhtml>
<args>
<modules>
<Mynamespace_catalogevent before="Enterprise_CatalogEvent">Mynamespace_CatalogEvent_Adminhtml</Mynamespace_catalogevent>
</modules>
</args>
</adminhtml>
</routers>
</admin>
I am trying to override the Enterprise/CatalogEvent/controllers/Adminhtml/Catalog/EventController.php.
The problem is the config.xml. How do I follow the naming convention of Magento.
The following is the config.xml file
<admin>
<routers>
<adminhtml>
<args>
<modules>
<Mynamespace_catalogevent before="Enterprise_CatalogEvent">Mynamespace_CatalogEvent_Adminhtml</Mynamespace_catalogevent>
</modules>
</args>
</adminhtml>
</routers>
</admin>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据上面看似正确的 xpath 和属性,您需要在 Mynamespace/CatalogEvent/controllers/Adminhtml/ 下有一个 EventController.php 文件。
这种重写风格是 Magento 中最新的(弃用以前的方法)。实际上,您在 Enterprise 目录之前注入一个目录,路由将从那里开始。由于控制器类定义不可用于自动加载器,因此通过采用模块参数并将其转换为目录来包含它们。在核心 Magento 路由中,控制器文件是通过
Mage_Core_Controller_Varien_Router_Standard::getControllerFileName()
和Mage_Core_Model_Config::getModuleDir()
(等等)确定的。它的评估方式意味着在模块中的两个目录级别(例如 Mynamespace/CatalogEvent)之后,下一个目录将是“controllers”。确保您的 EventController 类定义根据上述内容定位,您的操作与您要覆盖的操作匹配,并且您的类名与您的路径匹配,然后您就可以开始了。
困难的是,如果您的结构和语法有任何问题(保存不正确的类名),路由器最终将解析为企业操作控制器。
Based on the seemingly correct xpath and attribute above, you will need to have an EventController.php file under Mynamespace/CatalogEvent/controllers/Adminhtml/.
This style of rewrite is the latest in Magento (deprecating previous methods). Effectively, you are injecting a directory before the Enterprise directory, and routing will start there. Because controller class definitions are not available to the autoloader, they are included by taking the module argument and translating that to a directory. In core Magento routing though the controller file is determined via
Mage_Core_Controller_Varien_Router_Standard::getControllerFileName()
andMage_Core_Model_Config::getModuleDir()
(among others). The way that it's evaluated means that after two directory levels in your module (eg. Mynamespace/CatalogEvent), the next directory will be "controllers".Ensure that your EventController class definition is located according to the above, that your action matches the action you are overriding, and that your classname matches your path, and you'll be good to go.
The difficult thing is that if anything is "off" about your structure and syntax (save the incorrect classname), the router will end up resolving to the Enterprise action controller.
我遇到了类似的问题,解决我的问题的简单方法是确保该类的 _Adminthml 部分包含在我的本地控制器以及我要覆盖的控制器中。在您的情况下:
您的示例在
before
属性上缺少_Adminhtml
。这是 Magento Enterprise v1.12.0.2
希望这会有所帮助。
I was having a similar issue, and the simple solution to my problem was to ensure that the
_Adminthml
portion of the class was included in both my local controller as well as the controller I was overridding. In your case:Your example is missing the
_Adminhtml
on thebefore
attribute.This is on Magento Enterprise v1.12.0.2
Hope this helps.