SocialEngine 4 - 获取动作名称

SocialEngine 4 - get Action name

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

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

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

通常会在控制器中执行 public 函数 sculpturenameAction() 函数,但是,我想拦截动作名称并执行一个不同的函数将根据动作名称为个人雕塑页面提供数据。

这可能吗?我该怎么做?

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 !!