Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change page title in CakePHP 2.5?

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.

like image 776
mrdaliri Avatar asked Oct 13 '14 16:10

mrdaliri


2 Answers

Use

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

inside controller.

like image 122
Pratik Avatar answered Sep 29 '22 19:09

Pratik


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

like image 39
Abhishek Avatar answered Sep 29 '22 18:09

Abhishek