Table of Contents : Le Manuel

Les attributs en relation avec la page : $layout et $pageTitle

A few attributes exist in CakePHP controllers that give you control over how your views set inside of a layout.

The $layout attribute can be set to the name of a layout saved in /app/views/layouts. You specify a layout by setting $layout equal to the name of the layout file minus the .ctp extension. If this attribute has not been defined, CakePHP renders the default layout. If you haven’t defined one at /app/views/default.ctp, CakePHP’s core default layout will be rendered.

<?php

#   Using $layout to define an alternate layout

class RecipesController extends AppController {
    function quickSave() {
        $this->layout = 'ajax';
    }
}

?>
  1. <?php
  2. # Using $layout to define an alternate layout
  3. class RecipesController extends AppController {
  4. function quickSave() {
  5. $this->layout = 'ajax';
  6. }
  7. }
  8. ?>

The $pageTitle controller attribute allows you to set the title of the rendered page. In order for this to work properly, your layout needs to include the $title_for_layout variable, at least between <title> tags in the head of the HTML document.

Just set $pageTitle to a string you’d like to see in the <title> of your document.