3.5.3.1.1 set
set(string $var, mixed $value)
set(string $var, mixed $value)
The set() method is the main way to send data from your controller to your view. Once you've used set(), the variable can be accessed in your view.
<?php
//First you pass data from the controller:
$this->set('color', 'pink');
//Then, in the view, you can utilize the data:
?>
You have selected <?php echo $color; ?> icing for the cake.
<?php//First you pass data from the controller:$this->set('color', 'pink');//Then, in the view, you can utilize the data:?>You have selected <?php echo $color; ?> icing for the cake.
The set() method also takes an associative array as its first parameter. This can often be a quick way to assign a set of information to the view. Note that your array keys will be inflected before they get assigned to the view (‘underscored_key’ becomes ‘underscoredKey’, etc.):
<?php
$data = array(
'color' => 'pink',
'type' => 'sugar',
'base_price' => 23.95
);
//make $color, $type, and $basePrice
//available to the view:
$this->set($data);
?>
<?php$data = array('color' => 'pink','type' => 'sugar','base_price' => 23.95);//make $color, $type, and $basePrice//available to the view:$this->set($data);?>
See comment for this section
