[英]deal with layout.phtml in zend framework 1
I am following this tutorial(Getting Started with Zend Framework 1.11): http://akrabat.com/wp-content/uploads/Getting-Started-with-Zend-Framework.pdf 我正在关注本教程(Zend Framework 1.11入门): http : //akrabat.com/wp-content/uploads/Getting-Started-with-Zend-Framework.pdf
on page 10,zf-tutorial/application/layouts/scripts/layout.phtml, the code changed from: 在第10页,zf-tutorial / application / layouts / scripts / layout.phtml上,代码已更改为:
<?php echo $this->layout()->content; ?>
to: 至:
<?php
$this->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
$this->headTitle()->setSeparator(' - ');
$this->headTitle('Zend Framework Tutorial');
echo $this->doctype(); ?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<?php echo $this->headMeta(); ?>
<?php echo $this->headTitle(); ?>
</head>
<body>
<div id="content">
<h1><?php echo $this->escape($this->title); ?></h1>
<?php echo $this->layout()->content; ?>
</div>
</body>
Question: 题:
the output is the same, why need to change the code? 输出是一样的,为什么需要更改代码?
after I run the original code: <?php echo $this->layout()->content; ?>
在运行原始代码后: <?php echo $this->layout()->content; ?>
<?php echo $this->layout()->content; ?>
, in page source code: there is such output: <!DOCTYPE HTML PUBLIC....
after I run the modified code, in page source code, <!DOCTYPE HTML PUBLIC....
supposed to appear twice, one from $this->headMeta()...
, one from <?php echo $this->layout()->content; ?>
<?php echo $this->layout()->content; ?>
,在页面源代码中:有这样的输出: <!DOCTYPE HTML PUBLIC....
在运行修改后的代码后,在页面源代码中, <!DOCTYPE HTML PUBLIC....
应该出现两次,其中之一$this->headMeta()...
,其中一个来自<?php echo $this->layout()->content; ?>
<?php echo $this->layout()->content; ?>
, but it only appears one time, why? <?php echo $this->layout()->content; ?>
,但是只出现一次,为什么?
On page 10 you have the answer to your question: 在第10页上,您可以找到问题的答案:
Common HTML code: Layouts 常见的HTML代码:布局
It also very quickly becomes obvious that there will be a lot of common HTML code in our views for the header and footer sections at least and maybe a side bar or two also. 很快就很明显,在我们的视图中,至少对于页眉和页脚节,将有很多通用的HTML代码,也可能有一个或两个侧边栏。 This is a very common problem and the Zend_Layout component is designed to solve this problem. 这是一个非常常见的问题,而Zend_Layout组件旨在解决此问题。 Zend_Layout allows us to move all the common header, footer and other code to a layout view script which then includes the specific view code for the action being executed. Zend_Layout允许我们将所有通用的页眉,页脚和其他代码移动到布局视图脚本中,然后该脚本包括针对所执行动作的特定视图代码。
If you're getting duplicated results you must be including all those common header definition in both view and layout . 如果要得到重复的结果,则必须在视图和布局中都包含所有这些通用的标头定义。 Make sure to remove them from your views . 确保从视图中删除它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.