8

From 2.5 Migration Guide:

$title_for_layout is deprecated. Use $this->fetch('title'); and $this->assign('title', 'your-page-title'); instead.

They work in Views, but what to do in Controller? Using $this->assign() throws Fatal error.

mrdaliri
  • 7,148
  • 22
  • 73
  • 107

3 Answers3

7

Use

$this->set('title_for_layout', 'List User');

inside controller.

Pratik Joshi
  • 11,485
  • 7
  • 41
  • 73
5

You have to use

$this->assign('title',$title); 

in view files.

In layout, You can also use

$this->fetch('title', $title); 

to set the title

You can use $this->set('title_for_layout',$title); but you should not as it will be removed very soon

Abhishek
  • 795
  • 9
  • 20
  • 1
    thanks, I know what to do in View files (including layouts), question was about Controllers, which r3mmel posted the answer. – mrdaliri Oct 14 '14 at 08:53
  • whatever works for you is great, but i am still confused over how $this->assign('title', 'your-page-title'); can throw fatal error in view, i thought you added that on your controller – Abhishek Oct 14 '14 at 09:07
  • Yes I used it in Controller, not in View. (re-read first post again, plz) – mrdaliri Oct 15 '14 at 18:20
4

just set this in your controller's function()

$title = 'Title of your page | Site';
$this->set(compact('title'));

then you can use $title in your views to change the title of your page. :)

r3mmel
  • 656
  • 4
  • 13