zend框架中的layout.phtml问题1

时间:2013-04-25 02:46:25

标签: php zend-framework

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

以上代码取自本教程:http://akrabat.com/wp-content/uploads/Getting-Started-with-Zend-Framework.pdf它位于第10页,文件为:zf-tutorial/application/layouts/scripts/layout.phtml

问题:

  1. 这条线是什么? $this->headTitle()->setSeparator(' - ');

  2. 为什么我们需要这一行:<?php echo $this->escape($this->title); ?>我猜'逃避'是为了安全,但这在什么意思呢?

1 个答案:

答案 0 :(得分:1)

$this->escape()

默认情况下,escape()方法使用PHP htmlspecialchars()函数进行转义。 Escaping Output

$ this-&gt; headTitle() - &gt; setSeparator(' - ');

向标题添加多个值时setSeparator会使用指定的分隔符分隔标题。Head Title

<?php
$request = Zend_Controller_Front::getInstance()->getRequest();
$this->headTitle($request->getActionName())
     ->headTitle($request->getControllerName());
$this->headTitle('Zend Framework');   
$this->headTitle()->setSeparator(' - ');
?>   

<?php echo $this->headTitle() ?>将创建<title>action - controller - Zend Framework</title>