The Controller::set( ) method is just a way to pass a variable from the controller to the view. The basic syntax is $this->set('varname', $value).

There isn't really a formalized or "right" way to use the method, or how to name your variables. Just code to preference.

However, $this->data and $this->params['data'] (functionally equivalent; the former was added post-1.0 for the sake of less typing) are special variables that get passed to the view automatically. They have special significance for form fields and the like.

z. said on August 25, 2006

This works really well. If you have a logged in user:

$this->data = $this->Session->read("User");

?php echo $html->input("User/name",array()); ?

will be auto populated, and as many other fields you want to add to the form! becareful of overhead though

Sorry, comments are closed for this post. If you have any further questions or comments, feel free to send them to me directly.