Table of Contents : Le Manuel

L'attribut Paramètres ($params)

Controller parameters are available at $this->params in your CakePHP controller. This variable is used to provide access to information about the current request. The most common usage of $this->params is to get access to information that has been handed to the controller via POST or GET operations.

$this->params['form']

Any POST data from any form is stored here, including information also found in $_FILES.

$this->params['bare']

Stores 1 if the current layout is empty, 0 if not.

$this->params['isAjax']

Stores 1 if the current layout is set to ‘ajax’, 0 if not. This variable is only set if the RequestHandler Component is being used in the controller.

$this->params['controller']

Stores the name of the current controller handling the request. For example, if the URL /posts/view/1 was requested, $this->params['controller'] would equal "posts".

$this->params['action']

Stores the name of the current action handling the request. For example, if the URL /posts/view/1 was requested, $this->params['action'] would equal "view".

$this->params['pass']

Stores the GET query string passed with the current request. For example, if the URL /posts/view/?var1=3&var2=4 was requested, $this->params['pass'] would equal "?var1=3&var2=4".

$this->params['url']

Stores the current URL requested, along with key-value pairs of get variables. For example, if the URL /posts/view/?var1=3&var2=4 was called, $this->params['url'] would contain:

[url] => Array
(
    [url] => posts/view
    [var1] => 3
    [var2] => 4
)
  1. [url] => Array
  2. (
  3. [url] => posts/view
  4. [var1] => 3
  5. [var2] => 4
  6. )

$this->data

Used to handle POST data sent from the FormHelper forms to the controller.

<?php

// The FormHelper is used to create a form element:

$form->text('User.first_name');

// When rendered, it looks something like:

<input name="data[User][first_name]" value="" type="text" />

// When the form is submitted to the controller via POST,
// the data shows up in $this->data.

//The submitted first name can be found here:
$this->data['User']['first_name'];

?>
  1. <?php
  2. // The FormHelper is used to create a form element:
  3. $form->text('User.first_name');
  4. // When rendered, it looks something like:
  5. <input name="data[User][first_name]" value="" type="text" />
  6. // When the form is submitted to the controller via POST,
  7. // the data shows up in $this->data.
  8. //The submitted first name can be found here:
  9. $this->data['User']['first_name'];
  10. ?>

form

$this->params['form']
  1. $this->params['form']

Any POST data from any form is stored here, including information also found in $_FILES.

bare

$this->params['bare']
  1. $this->params['bare']

Stores 1 if the current layout is empty, 0 if not.

isAjax

$this->params['ajax']
  1. $this->params['ajax']

Stores 1 if the current layout is set to ‘ajax’, 0 if not. This variable is only set if the RequestHandler Component is being used in the controller.

controller

$this->params['controller']
  1. $this->params['controller']

Stores the name of the current controller handling the request. For example, if the URL /posts/view/1 was requested, $this->params['controller'] would equal "posts".

action

$this->params['action']
  1. $this->params['action']

Stores the name of the current action handling the request. For example, if the URL /posts/view/1 was requested, $this->params['action'] would equal "view".

pass

$this->params['pass']
  1. $this->params['pass']

Stores the GET query string passed with the current request. For example, if the URL /posts/view/?var1=3&var2=4 was requested, $this->params['pass'] would equal "?var1=3&var2=4".

url

$this->params['url']
  1. $this->params['url']

Stores the current URL requested, along with key-value pairs of get variables. For example, if the URL /posts/view/?var1=3&var2=4 was called, $this->params['url'] would contain:

[url] => Array
(
    [url] => posts/view
    [var1] => 3
    [var2] => 4
)
  1. [url] => Array
  2. (
  3. [url] => posts/view
  4. [var1] => 3
  5. [var2] => 4
  6. )

data

$this->data
  1. $this->data

Used to handle POST data sent from the FormHelper forms to the controller.

<?php

// The FormHelper is used to create a form element:

$form->text('User.first_name');

// When rendered, it looks something like:

<input name="data[User][first_name]" value="" type="text" />

// When the form is submitted to the controller via POST,
// the data shows up in $this->data.

//The submitted first name can be found here:
$this->data['User']['first_name'];

?>
  1. <?php
  2. // The FormHelper is used to create a form element:
  3. $form->text('User.first_name');
  4. // When rendered, it looks something like:
  5. <input name="data[User][first_name]" value="" type="text" />
  6. // When the form is submitted to the controller via POST,
  7. // the data shows up in $this->data.
  8. //The submitted first name can be found here:
  9. $this->data['User']['first_name'];
  10. ?>