set() method provides a way to set values in our cake-php controller so that we can use it in our view for presentation.
Syntax of set is: $this->set('variable','value')
In cakephp controller, we can set the values as
<?php
$this->set('var1','value1');
$this->set('var2','value2');
$this->set('var3','value3'); ?>
In above code , we are using 3 set method to set variables to use it in view but we can do the same in a single set method using compact() method.
Example: To set more than one variable/value in our controller
$var1 = value1; $var2 = value2; $var = value3;
$this->set(compact('var1','var2','var3'));
0 Comment(s)