【问题标题】:SocialEngine 4 - get Action nameSocialEngine 4 - 获取动作名称
【发布时间】:2015-03-27 14:22:15
【问题描述】:

找人告诉我如何从模块核心控制器中获取动作名称,而不是执行动作,而是使用动作名称作为变量来确定要输出的内容。

基本上,我正在切换到 SocialEngine 而不是我的 wordpress 安装,为了保持我的旧页面结构,我正在设置用于提取页面输出的模块。所以,我为雕塑设置了一个Controller,然后将每个雕塑数据存储在一个数据库表中。

因此,当有人访问 MyDomain/sculptures 时,他们会从数据库中获取一个列表,该列表会动态生成用于导航到各个雕塑页面的 url……当然,这将是MyDomain/scultures/sculpturename

这通常会在控制器中执行 public functionsculpturenameAction() 函数,但是,我想截取动作名称并执行一个不同的函数,该函数将为单个雕塑页面提供数据基于动作名称。

这可能吗?我该怎么做?

【问题讨论】:

    标签: module controller action core socialengine


    【解决方案1】:
    You can get the current module, controller and action name using below code:
    
    $front = Zend_Controller_Front::getInstance();
    $module = $front->getRequest()->getModuleName();
    $controller = $front->getRequest()->getControllerName();
    $action = $front->getRequest()->getActionName();
    
    If you want to divert the route or want to run some other code at some action than you can use the routeShutdown() method. Please see the below example for this:
    
        class yourModuleName_Plugin_Core extends Zend_Controller_Plugin_Abstract {
    
            public function routeShutdown(Zend_Controller_Request_Abstract $request) {
    
                $module = $request->getModuleName();
                $controller = $request->getControllerName();
                $action = $request->getActionName();
    
                //ADD YOUR ACTION CONDITION
                if ($module == 'core' && $controller == 'index' && $action == 'index') {
    
                    //SET SOME OTHER ACTIONS OR YOU CAN WRITE SOME OTHER CODE
                    $request->setModuleName('yourModuleName');
                    $request->setControllerName('yourControllerName');
                    $request->setActionName('yourActionName');
                }
            }
        }
    
    Hope this answer will helps you. Thank you !!
    

    【讨论】:

    • 谢谢@Jitendra Bansal 这读起来好像是我正在寻找的,但类声明并不完全是我在做的。我没有创建插件...这是我使用的:class Core_SculpturesController extends Core_Controller_Action_Standard {
    • 是的,Ryan,你可以在你的控制器类中使用下面的代码找到动作名称: $front = Zend_Controller_Front::getInstance(); $action = $front->getRequest()->getActionName();但是,如果您想将路线转移到其他操作,则必须使用 routeShutdown() 方法。如果有任何疑问,请告诉我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多