【问题标题】:using Zend View Action Helpers & disabling layout使用 Zend View Action Helpers 和禁用布局
【发布时间】:2010-07-22 13:29:04
【问题描述】:

我只是在阅读 zend 框架文档上的 zend view action helpers。所以我创建了一个索引操作

// index.phtml
... 
echo $this->action(
  $action = "widgetenabledoutput",
  $controller = "index",
  $module = null,
  array(
    "noLayout" => true,
    "itemsPerPage" => 15
  )
);

// index controller (IndexController.php)
public function widgetenabledoutputAction() {
  $noLayout = $this->getRequest()->getParam("noLayout");
  $itemsPerPage = $this->getRequest()->getParam("itemsPerPage");

  if ($noLayout) { // i made this such that this page/action can be displayed with layout and without. 
    $this->_helper->layout->disableLayout();
  }
  $html = "<ul>";
  for ($i = 1; $i <= $itemsPerPage; $i++) {
    echo "<li>Item $i</li>";
  }
  $html .= "</ul>";
  $this->view->html = $html;     
}

我得到的错误是在索引操作 index.phtml 中,我的目的是获取 widgetenabledoutputAction 的输出(列表)而不是 widgetenabledoutputAction 的布局,但我想要 indexAction 的布局有道理?难道我做错了什么?还是我必须为我想使用动作助手的东西做一个微妙的动作?

【问题讨论】:

    标签: zend-framework


    【解决方案1】:

    如果您只想使用不同的视图,请使用

    $this-&gt;_helper-&gt;viewRenderer('index');

    您无需调用其他操作即可使用相同的视图

    【讨论】:

    • 我相信这会呈现索引操作?不确定,但我打算做或测试的是动作助手,允许我将来自另一个视图生成的内容添加到我当前的输出中
    【解决方案2】:

    我发现使用 zend 视图操作助手是智能 enuf 并自动禁用该视图的布局。所以它只提供该动作视图脚本的输出,而不是布局。我所做的似乎禁用了请求的布局,而不是我想要的。

    【讨论】:

      猜你喜欢
      • 2012-05-12
      • 1970-01-01
      • 1970-01-01
      • 2014-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多