2

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

Hensembryan
  • 1,067
  • 3
  • 14
  • 31

1 Answers1

8

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.

Ross
  • 18,117
  • 7
  • 44
  • 64
  • Whilst I'm at it, you are also using 1.2 syntax elsewhere; 1.3 allows, and recommends that you use `$this->Html->foo()` and `$this->Foo->bar()` in your views. See the [1.2-1.3 migration](http://book.cakephp.org/view/1561/Migrating-from-CakePHP-1-2-to-1-3) if you're interested. – Ross Jun 24 '11 at 19:25