【问题标题】:set/add view from controller action从控制器操作设置/添加视图
【发布时间】:2010-06-15 10:52:21
【问题描述】:

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

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

非常感谢。

【问题讨论】:

  • 你想输出另一个脚本的第二个脚本 INSEATD 还是连接它们?
  • 如果有人可以向我展示两种方法(替换或连接),那将是完美的。

标签: zend-framework view controller


【解决方案1】:

如果你只是想从控制器渲染一些其他的视图脚本:

$this->render('someotherview');

Wich 将渲染 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();
}

}

应该让你走上正轨!

还有

$this->renderScript('path/to/index.phtml');

效果很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多