【问题标题】:How do I call other Controllers within a Zend Framework Process and retrieve their rendered view?如何在 Zend 框架进程中调用其他控制器并检索它们的渲染视图?
【发布时间】:2011-04-20 11:51:00
【问题描述】:

我有以下设置:

一个无限运行的 PHP 进程,它查看包含模块名称、控制器名称、动作名称和参数数组的作业队列。

对于每个作业,我想调用给定的控制器操作并检索呈现的视图以进行进一步处理。

我正在考虑为每个作业引导一个 Zend_Application 实例,但不完全确定如何处理其余的。或许还有更好的办法。

所以我的问题是:

如何在 Zend 框架进程中调用其他控制器并检索它们的渲染视图?

提前感谢大家!

【问题讨论】:

    标签: php model-view-controller zend-framework controller message-queue


    【解决方案1】:
    $this->_forward('otherAction', 'otherControllerOrNull');
    

    http://framework.zend.com/manual/en/zend.controller.dispatcher.html

    您可以阅读此主题:Calling member function of other controller in zend framework?

    【讨论】:

    • 但这会将现有请求转发到指定的控制器/操作,对吗?在我看来,OP 想要捕获该控制器/动作的输出以用于 current 请求。
    • 没错,大卫,我想保持当前进程运行,只使用其他控制器产生的任何输出。 _forward 不允许这样做。
    • 你有没有找到解决这个问题的方法?
    【解决方案2】:

    我认为最好使用 Front_Controller 并分派一个新请求。

    类似这样的东西,来自你的控制器(不是工作代码):

        $frontController = $this->getFrontController();
    
        $newRequest = new Zend_Controller_Request_Http();
        $newRequest->setActionName('newAction');
        $newRequest->setControllerName('newController');
    
        $response = new Zend_Controller_Response_Http();
    
        $frontController->dispatch($newRequest, $response);
    

    可能没这么简单,但还是要考虑一下……

    【讨论】:

    • 成功了:$request = new Zend_Controller_Request_Http(); $this->getFrontController()->setResponse(new Zend_Controller_Response_Cli)->setRequest($request->setControllerName('testController')->setActionName('testAction'))->setRouter(new Zend_Controller_Router_Route)->setParam('noViewRenderer ', 真的); … 谢谢! :-)
    【解决方案3】:

    您不能使用Action View Helper 吗?如果你想在你的控制器中输出,那么你可以简单地使用$this->view->action('someAction', 'someController'); 或 ActionStack 帮助器。

    在任何一种情况下,请注意性能影响。详情请见Why the Zend Framework Actionstack is Evil

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-19
      • 2012-09-02
      • 1970-01-01
      • 2011-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-23
      相关资源
      最近更新 更多