从控制器动作设置/添加视图

Max*_*Max 1 zend-framework controller view

我正在尝试设置除了当前请求的操作视图脚本之外还要执行的视图脚本.我希望从控制器操作本身执行此操作,以便从布局$ this-> layout() - > content helper中获得此新视图脚本输出.

我找到了setView()方法,但不知道如何从控制器中使用它.

非常感谢.

Izn*_*ood 6

如果您只想从控制器渲染其他视图脚本:

$this->render('someotherview');
Run Code Online (Sandbox Code Playgroud)

将呈现someotherview.phtml.来自:http://framework.zend.com/manual/en/zend.controller.action.html#zend.controller.action.viewintegration.render

class MyController extends Zend_Controller_Action{
public function fooAction()
{
    // Renders my/foo.phtml
    $this->render();

    // Renders my/bar.phtml
    $this->render('bar');

    // Renders baz.phtml
    $this->render('baz', null, true);

    // Renders my/login.phtml to the 'form' segment of the
    // response object
    $this->render('login', 'form');

    // Renders site.phtml to the 'page' segment of the response
    // object; does not use the 'my/' subirectory
    $this->render('site', 'page', true);
}

public function bazBatAction()
{
    // Renders my/baz-bat.phtml
    $this->render();
}
Run Code Online (Sandbox Code Playgroud)

}

应该让你走上正轨!

$this->renderScript('path/to/index.phtml');
Run Code Online (Sandbox Code Playgroud)

工作得很好.