Wednesday, 22 June 2011

CakePHP - Parse Data From Controller To View

Let's say $a = '123', in index() in users_controller.
If we want to use the $a in users/index, we can use set() and compact():

$this->set(compact('a'));

*set() : Send data from controller to view.
**compact() : Creates an array containing variables and their values.
***Note that we need to remove the dollar($) sign when using compact().

Reference:
1. Stupid CakePHP Controller Tricks
2. Interacting with Views

No comments: