CakePHP设置pageTitle不起作用

时间:2011-06-24 19:14:11

标签: php cakephp page-title

当我尝试使用pageTitle变量在我的控制器中设置页面标题时,它不起作用。我的控制器代码:

class UsersController extends AppController {
    var $name = 'Users';

    function index() {
        $this->pageTitle = 'List User';
    }
}

我的布局代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php echo $html->charset(); ?>
<?php echo $html->css('admin'); ?>
<title><?php echo $title_for_layout; ?></title>
</head>

<body>
<!-- Container -->
<div id="container">

<!-- Header -->
<div id="header">
<?php echo $html->image('admin/logo.png', array('alt' => __('Bekz',true)))?>
</div>
<!-- /Header -->

<div id="menu">
&nbsp;
</div>

<!-- Content -->
<div id="wrapper">
<div id="content">

<?php if($session->check('Message.flash')) echo $session->flash(); ?>

<?php echo $content_for_layout; ?>

</div>
</div>
<!-- /Content -->

<!-- Left column -->
<div id="left">
</div>
<!-- /Left column -->

<!-- Right column -->
<div id="right">
</div>
<!-- /Right column -->

<!-- Footer -->
<!-- /Footer -->

</div>
<!-- /Container -->

</body>
</html>

我的cakePHP版本是1.3.1。我的代码有什么问题???

提前,

布赖恩

1 个答案:

答案 0 :(得分:8)

看起来你正在使用旧的语法。 (前1.3)

你应该这样做:

function index() {
    $this->set('title_for_layout', 'List User');
}

请注意title_for_layout与视图中$title_for_layout变量的相同之处。

使用set将数据分配给变量。