On 1 Lis, 10:58, Deane <[EMAIL PROTECTED]> wrote:
> I'm using the boilerplate code from the manual for some basic CRUD
> operations, and it's led to a question about how data gets into the
> template.
>
> In the "index" method of a controller, you see this:
>
> $this->set('Users', $this->User->findAll());
>
> So, we're explicitly assigning the results of findAll to the "Users"
> variable, which is then available in the view as $Users -- this makes
> sense.
>
When you set it this way, you can access this variable by simply using
$Users. This is good for displaying for example a list of users.
> But in the "edit" method, I see this:
>
> $this->data = $this->User->read();
>
> So we're assigning the results of the "read" method directly to the
> data array?
>
> I would expect to see something like this:
>
> $this->set('MyUser', $$this->User->read());
>
> Why the difference in setting view variables? I'm sure there's a
> logical reason for this, but can someone tell me what it is?
Here you are assigning a specific user to the data field of the
controller. This field has a special meaning. It is also available in
the view and should store a model data. This field is used by the html
helper when rendering input fields. When $html->input() detects that
there is a value in $this->data corresponding to the path given as a
parameter, it will render the input with the value from the model.
This way you can do editing without the need for manually assigning
the data for inputs from your own variables set by the $this->set()
function.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---