I'm kind of lost.
I made a sort of 'master page' th开发者_运维知识库at I want a page to use. Where do I declare it?
MainLayout.phtml
<html>
<head>
</head>
<body>
<?php echo $this->layout()->content; ?>
<div>
<ul>
<li><a href="#">Navigation</a></li>
<li><a href="#">Navigation</a></li>
<li><a href="#">Navigation</a></li>
<li><a href="#">Navigation</a></li>
<li><a href="#">Navigation</a></li>
</ul>
</div>
</body>
</html>
Index.phtml
<?php echo $this->doctype() ?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<?php echo $this->headMeta() ?>
<meta name="language" content="en" />
<title><?php echo $this->escape($this->title) ?></title>
</head>
<body>
<h1>This is the first page I made.</h1>
</body>
</html>
I'm using the Zend framework.
Basically, what Pascal said is correct: when Zend_Layout
is used, it will insert the content of the view script into the master layout where
echo $this->layout()->content;
is called. Since it is an insertion, you do not include the entire HTML page though. In your example, the template and the layout both contain a full page with HTML, HEAD and BODY elements, resulting in invalid markup.
However, since View Scripts are processed before Layout scripts, you can set the layout from the View script through the layout helper, using
$this->layout()->setLayout('foo');
You can also set the layout from the Controller
$this->_helper->layout->disableLayout();
And of course, like everything else in ZF, it is configurable from the application.ini as well. The Zend_Layout
Quickstart is really best start to learn about this component.
You don't say in any of those files that index.phtml
should be embedded in layout.phtml
: the Zend_Layout
component will do that for you :
- The content will be generated by the page (using index.phtml)
- And it will be injected into the
content
property of the layout (The name of that property is configurable, of course)
But all this has to be configured -- generally from your Bootstrap file, or using some configuration file.
For more informations and detailed explanations and examples, you might want to take a look at :
- Zend Framework's QuickStart
- And, more specifically, the chapter Create A Layout
- Or the e-book Zend Framework: Surviving The Deep End
- And, more specifically, Chapter 10. Setting The Design With Zend_View, Zend_Layout, HTML 5 and Yahoo! User Interface Library
精彩评论