Just to explain this a bit more:

The way $this->User->save() works depends on whether it can find an
id.  It first looks at $this->data['User']['id'], if that is empty it
then looks at $this->User->id and then if that is empty as well it
will insert rather than update.  This is fine but the catch comes
after the save.

After a model is inserted the last insert id is automatically assigned
to $this->User->id, therefore any successive calls to $this->User-
>save() will find $model->id and update the record with that id.

Calling $this->User->create() tell the User model that you want to
create a new entry and clears $this->User->id

Hope that clears up _why_ your problem was happening.

Geoff
--
http://lemoncake.wordpress.com

On Jun 28, 6:41 pm, majna <[EMAIL PROTECTED]> wrote:
>  Add befrore save
> $this->User->create();
>
> // save the imported user data
> $this->User->save($this->data);
>
> On Jun 28, 8:56 am, "Gould, Adrian" <[EMAIL PROTECTED]>
> wrote:
>
> > I am attempting to import a file that has been uploaded to a imports folder 
> > in the correct location...
>
> > I have had the import routine saving an entry, but when the next line is 
> > imported it does nto create a new record but updates the previous one.
>
> > How can I do this...
>
> >         // open the file for reading
> >         if (! $fd = @fopen($csvFile, "r")) {
> >                 die("Failed to open input file");
> >         }
>
> >         // set header to true
> >         $header = true;
> >         // read the file using the automatic csv conversion routines
> >         while ($fields = fgetcsv($fd)) {
>
> >                 // if it the header then skip the row
> >                 if ($header) { /* skip CSV header row */
> >                         $header = false;
> >                         continue;
> >                 }
> >                 else
> >                 {
> >                         // parse the imported data into the data array 
> > ready for saving
> >                         $this->data =  $this->__parse_csv_row($fields);
> >                         // save the imported user data
> >                         $this->User->save($this->data);
> >                 }
> >         }
>
> > Am I barking up the wrong tree on the way ->save works? Can I not get it to 
> > function this way?
>
> > Thanks
>
> > Ady


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to