【问题标题】:show result of action in new place (without use of $this->layout()->content; )在新位置显示操作结果(不使用 $this->layout()->content; )
【发布时间】:2011-08-06 05:04:41
【问题描述】:
<?php echo $this->layout()->content; ?>

上面的代码导致$this-&gt;layout()-&gt;content 显示在布局文件的每个位置。但是我需要粒度来显示其他地方的某些操作的结果(例如在右列或左列中)。

这是布局文件:

<div class="center_col"><?php echo $this->layout()->content; ?></div>
<div class="right_col">?????</div>

我如何在提供的(上方).right_col 中显示某些操作的结果?

【问题讨论】:

标签: zend-framework layout view


【解决方案1】:

一种方法是定义您自己的布局占位符(即除了“内容”之外)。例如:

<div class="center_col"><?php echo $this->layout()->content; ?></div>
<div class="right_col"><?php echo $this->layout()->rightColumn; ?></div>

然后在你的操作中你需要告诉 Zend_Layout 使用新的内容占位符,例如:

public function testAction() { 
    // ....
    // render output of this action in 'rightColumn' placeholder
    // rather than in default 'content' placeholder.      
    $this->view->layout()->setContentKey('rightColumn');            
}

或者,您也可以查看placeholder 查看助手。使用助手,您可以执行以下操作:

<div class="center_col"><?php echo $this->layout()->content; ?></div>
<div class="right_col"><?php echo $this->placeholder('right_col'); ?></div>

帮助器有许多可以简化其内容管理的功能。

希望这会有所帮助。

【讨论】:

  • thanx Marcin ,一如既往的完美 ;)
  • @afsane。我很高兴能帮上忙 :-)
  • @Marcin 第一个代码示例(添加 $this->layout()->rightcolumn)不是要求您将其添加到每个控制器吗?
猜你喜欢
  • 2011-12-16
  • 1970-01-01
  • 1970-01-01
  • 2012-03-21
  • 2012-11-13
  • 1970-01-01
  • 2020-04-21
  • 2021-10-21
  • 1970-01-01
相关资源
最近更新 更多