Re: $model-save - which id is used?

2009-05-10 Thread JamesF

on edit it uses the id of the record you pulled up. on add it uses the
next auto-incremented id.

On May 8, 11:18 am, Jonathan jst...@image.dk wrote:
 Here is a pretty simple save example from the manual:

 function edit($id) {
     if(!empty($this-data)) {
         if($this-Recipe-save($this-data)) {
             ...
         }
     }

 }

 Somehow save knows which Recipe id to update, but we never tell it -
 and it is not part of $this-data. How does save know it?

   Regards

     Jonathan
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: $model-save - which id is used?

2009-05-10 Thread jstein

On May 10, 8:25 am, JamesF usaexportexpe...@gmail.com wrote:

 on edit it uses the id of the record you pulled up.

Thanks for your reply, - but I don't pull up anything before I call
save...

The id of the record to be modified is only present as a parameter to
the edit function. In some auto-magic way, the model learns about
this id. But how?

  Regards

Jonathan

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: $model-save - which id is used?

2009-05-10 Thread Rick

Take a look at $this-Recipe.  I think it is in there.

debug($this-Recipe);



On May 10, 7:33 am, jstein jst...@image.dk wrote:
 On May 10, 8:25 am, JamesF usaexportexpe...@gmail.com wrote:

  on edit it uses the id of the record you pulled up.

 Thanks for your reply, - but I don't pull up anything before I call
 save...

 The id of the record to be modified is only present as a parameter to
 the edit function. In some auto-magic way, the model learns about
 this id. But how?

   Regards

     Jonathan

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: $model-save - which id is used?

2009-05-10 Thread Enrique

The id can be found in $this-data.
$this-data is automatically filled by the submitted form data and the
form sends the id with the post data.
The action parameter $id is only used to load the model and fill in
the form.

Hope that answers your question.

- Enrique

On 8 Mai, 12:18, Jonathan jst...@image.dk wrote:
 Here is a pretty simple save example from the manual:

 function edit($id) {
     if(!empty($this-data)) {
         if($this-Recipe-save($this-data)) {
             ...
         }
     }

 }

 Somehow save knows which Recipe id to update, but we never tell it -
 and it is not part of $this-data. How does save know it?

   Regards

     Jonathan

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: $model-save - which id is used?

2009-05-10 Thread jstein

On May 10, 4:35 pm, Rick will...@gmail.com wrote:

 Take a look at $this-Recipe.  I think it is in there.

 debug($this-Recipe);

Yes - $this-Recipe-id is set to the correct id - but then again:
How?

  Regards

Jonathan

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: $model-save - which id is used?

2009-05-10 Thread Miles J

Thats how CakePHP is built, wonderful right?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: $model-save - which id is used?

2009-05-10 Thread jstein

On May 10, 5:52 pm, Enrique enrique.jaco...@gmail.com wrote:

 The id can be found in $this-data.

No. My first thought was that the form helper would insert a hidden
field with the id - but it doesn't (and debug($this-data) shows that
the id is not present in the data).

Now I did some investigations, and I guess that if a controller uses
only one model, this model is initialized with the id set to the first
parameter passed to the action. So if you call /tests/action/123, then
$this-Test-id will be 123.

This seems to be done in the controllers constructClasses() method:
http://api.cakephp.org/view_source/controller/#line-426

Please correct me if I'm wrong - otherwise I'll see if I can add a
note to the documentation.

  Regards

Jonathan

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: $model-save - which id is used?

2009-05-10 Thread Miles J

Yes its all done in the initializing of the controllers/models, not
within the forms.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



$model-save - which id is used?

2009-05-08 Thread Jonathan

Here is a pretty simple save example from the manual:

function edit($id) {
if(!empty($this-data)) {
if($this-Recipe-save($this-data)) {
...
}
}
}

Somehow save knows which Recipe id to update, but we never tell it -
and it is not part of $this-data. How does save know it?

  Regards

Jonathan

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---