2

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.

Inigo Flores
  • 4,461
  • 1
  • 15
  • 36
Helping Hands
  • 5,292
  • 9
  • 60
  • 127

2 Answers2

3

Since CakePHP 2.5, the right way of setting the title is as follows:

In your layout:

$this->fetch('title')

In you view:

$this->assign('title', 'My Page Title')

The same applies to the meta tags:

In your layout:

<? echo $this->Html->meta('keywords',$this->fetch('keywords'));?>
<? echo $this->Html->meta('description',$this->fetch('description'));?>

In you view:

<? $this->assign('keywords', 'My meta tags')?>
<? $this->assign('description', 'My description')?>

More on CakePHP Layouts.

Inigo Flores
  • 4,461
  • 1
  • 15
  • 36
0

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 the default.ctp, where you can display it:

<title>
    <?php echo $seotitel ?>
</title>

N.B. this is untested due to lack of a running 2.6 instance.

code-kobold
  • 829
  • 14
  • 18