magento控制器的动态路由器名称 [英] Dynamic router name for magento controller
问题描述
从用户可以在管理区域中随意配置并在自定义模块中自动更新的意义上说,我将如何创建一个具有动态名称为控制器的自定义模块?
How would I go about creating a custom module that has a controller with an action name that is dynamic, in the sense that it can be configured by the user in the admin area at will and be automatically updated in the custom module?
推荐答案
我认为您可以通过在控制器上使用魔术php方法__call
来解决此问题.
I think you can approach this by using magic php method __call
on your controller.
我假设您将动作名称存储在名为"mymodule/controller/action"的Magento配置中,因此您可以使用:
I assumed that you store your action name in a Magento config named 'mymodule/controller/action', so you can get the value using :
Mage::getStoreConfig('mymodule/controller/action');
然后您拥有控制器,例如Mymodule/controllers/TestController.php
Then you have the controller for example Mymodule/controllers/TestController.php
然后将方法添加到该控制器中,如下所示:
And you add the method in that controller like this :
public function __call($method, $arg) {
if ($method == Mage::getStoreConfig('mymodule/controller/action')) {
//Do whatever you want
}
}
这将使您的控制器//使用您在配置中指定的操作访问控制器时执行所需的任何操作.基本思路就是这样.希望这会有所帮助.
This will make your controller //Do whatever you want when you accessing it using the action you specified in the config. The basic idea is like that. Hope this helps.
这篇关于magento控制器的动态路由器名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!