Search code examples
phpcakephppage-title

CakePHP set pageTitle not working


When i tried to set page title in my controller using pageTitle variable it not work. My controller code:

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

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

my layout code:

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

My cakePHP version is 1.3.1. What's wrong with my code ???

thx in advance,

Brian


Solution

  • Looks like you're using the old syntax. (Pre 1.3)

    You should do:

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

    Notice how title_for_layout is the same as the $title_for_layout variable in your view.

    Use set to assign data to variables.