I am new to Cakephp and searching for how to set page titles and meta keywords,desc. for best SEO management.
I have checked any tutorials and question , I would like to ask that is it necessary to set up title in controller page and then fetch in any page of VIEW/mypage?
I am trying to set direct title in my home page in a way like :
$this->set('title', 'My Page Title');
But this is not working , Is there any way to direct set title without connection with controller?
I am using Version 2.6.3 of CakePhp.
2
Answers
The title tag would be set in the default.ctp of the layout in use, e.g.
app/View/Layouts/default.ctp
. You can hardcode your values there.The displayed value comes from the
PagesController::display()
(app/Controller/PagesController.php
), generated from the directory the rendered view resides in.Setting your SEO title in a controller
$this->set('seotitel', 'Foo')
should propagate the value to thedefault.ctp
, where you can display it:N.B. this is untested due to lack of a running 2.6 instance.
Since CakePHP 2.5, the right way of setting the title is as follows:
In your layout:
In you view:
The same applies to the meta tags:
In your layout:
In you view:
More on CakePHP Layouts.