How does Zend link $this->layout()->content with scripts/index/index.phtml?
I think I'开发者_如何学编程m failing to understand the basics of how the pages are supposed to stick together. I've looked at the quick start on the zend site but it's far too simplistic.
So as Tomáš Fejfar explained that's how the $this->layout()->content
works. Yet what is interesting is that 'content' is not just a variable in the layout. In fact, 'content' is a key in a View placeholder called 'Zend_Layout'. For this reason, the following snippets are equivalent to echo $this->layout()->content
in your layout.phtml:
$placeHolder = Zend_View_Helper_Placeholder_Registry::getRegistry()->getContainer('Zend_Layout');
echo $placeHolder['content'];
// or
echo $this->placeholder('Zend_Layout');
// or
echo $this->placeholder('Zend_Layout')->content;
This can be very useful. What I mean is that you can define some places in your layout.phtml that will be display values of your custom keys from 'Zend_Layout' placeholder. For instance, imagine that you would like to have a layout.phtml and you want to be able to modify text in your footer. You could do this by defining layout.phtml which will contain the following in the footer:
<div id="footer">
<?php echo $this->layout()->myFooterText; ?>
</div>
You could setup a default value for this footer in e.g. your Bootstrap.php. However, if you wanted you could modify this text in your actions as follows;
$this->view->placeholder('Zend_Layout')->myFooterText = 'Some text only for this action';
That's it what I wanted to add. Off course one could think of other scenerios, because $this->view->placeholder('Zend_Layout')
is an instance of Zend_View_Helper_Placeholder_Container
so you could do other things with Zend_Layout placeholder.
EDIT: Key 'content' is a default name. You can change it to something else using setContentKey method of Zend_Layout, e.g.:
protected function _initSetNewLayoutContentKey() {
$layout = $this->bootstrap('layout')->getResource('layout');
// instead of 'content' use 'viewoutput'
$layout->setContentKey('viewoutput');
}
With this change, in your layout.phtml you would use echo $this->layout()->viewoutput;
instead of echo $this->layout()->content;
.
What's rendered in your view (the PHTML file) is saved into the content variable. That can be echoed in the layout template (another phtml file - preferably layout.phtml). And that'S the 'final product' :) (or maybe you want to specify you question more).
Layout is nothing more then a controller plugin which creates its own view after all dispatching has been done so it can take final response object and sets the content property of its view to response body .
So basically in your case buffer of index.phtml , gets stored in response object first then later layout takes this value and change it its own view buffer .
精彩评论