在新地方显示行动结果(不使用$ this-> layout() - > content;)

afs*_*ane 3 layout zend-framework view

<?php echo $this->layout()->content; ?>
Run Code Online (Sandbox Code Playgroud)

上面的代码导致$this->layout()->content在布局文件中的每个位置显示.但我需要粒度来在另一个地方显示某些操作的结果(例如,在右列或左列中).

这是布局文件:

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

我如何能够在所提供的(上图)中显示某些行为的结果.right_col

Mar*_*cin 5

一种方法是定义自己的布局占位符(即"内容"除外).例如:

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

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

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

或者,您也可以查看占位符视图助手.有了助手,你可以这样做:

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

帮助程序具有许多功能,可以简化其内容的管理.

希望这会有所帮助.