skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search