0
<?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”是为了安全,但它在这里究竟意味着什么?

4

1 回答 1

1

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

于 2013-04-25T07:19:03.697 回答