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

时间:2011-04-15 09:50:42

标签: zend-framework layout view

<?php echo $this->layout()->content; ?>

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

这是布局文件:

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

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

1 个答案:

答案 0 :(得分:5)

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

<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>

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

希望这会有所帮助。