布局.zend framework中的php问题


<?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); ?>我猜'escape'是为了安全,但它在这里实际上是什么意思?

$this->escape()

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

$ this -> headTitle()——> setSeparator (' - ');

当你为标题添加多个值时,setSeparator将用指定的分隔符分隔标题。标题

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

最新更新