How to change page title in CakePHP 2.5?

◇◆丶佛笑我妖孽 提交于 2019-12-08 17:03:46

问题


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.


回答1:


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. :)




回答2:


Use

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

inside controller.




回答3:


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



来源:https://stackoverflow.com/questions/26345051/how-to-change-page-title-in-cakephp-2-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!