Re: multiple line file import problem.

2007-06-28 Thread majna

 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
-~--~~~~--~~--~--~---



Re: multiple line file import problem.

2007-06-28 Thread Geoff Ford

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
-~--~~~~--~~--~--~---



RE: multiple line file import problem.

2007-06-28 Thread Gould, Adrian


Thanks Geoff - yes it does, but still struggling to get it to save the data.

The query generated is: INSERT INTO `users` (`created`,`modified`) VALUES 
('2007-06-28 18:33:46','2007-06-28 18:33:46')

$people = $this-__convert_csv($uploadfile);
foreach( $people as $person) {

$this-User-create();

foreach( $person as 
$dataKey=$dataItem) {

$this-details['User'][$dataKey]= $dataItem;
} // end foreach

echo 'pre style=text-align:left';
print_r($this-details);echo br /;
echo /pre;


if($this-User-save()) {
$this-Session-setFlash('The 
User has been saved');
} else {

$this-Session-setFlash('Please correct errors below.');
}

the $this-details contains:

Array
(
[User] = Array
(
[student_id] = 1234567890
[staff_id] = 
[role_id] = 1
[given_names] = John
[last_name] = Doe
[preferred_name] = John
[username] = DoeJ
[passwd] = gfdgJF8
[passwd_encrypted] = f7fd264e428a7f56edc94b6b71cbc5b5
[locked_out] = 0
[attempts] = 0
[campus_id] = 1
[current_year] = 2007
[current_semester] = 1
[directory] = 
)
)

This successflly inserts a blank row for each row of the data int eh file...

if I put
if($this-User-save($this-details)) {

the result is an 'please correct the errors below'.

GRumbles!

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



RE: multiple line file import problem.

2007-06-28 Thread Gould, Adrian

Thanks Maj... 


-Original Message-
From: cake-php@googlegroups.com on behalf of majna
Sent: Thu 6/28/2007 16:41
To: Cake PHP
Subject: Re: multiple line file import problem.
 

 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
-~--~~~~--~~--~--~---



Re: multiple line file import problem.

2007-06-28 Thread Geoff Ford

You are not assigning $this-details anywhere.

if($this-User-save()) {
$this-Session-setFlash('The User has been saved');
}

Should be

if($this-User-save($this-details)) {
 $this-Session-setFlash('The User has been saved');
}

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

On Jun 28, 8:41 pm, Gould, Adrian [EMAIL PROTECTED]
wrote:
 Thanks Maj...

 -Original Message-
 From: cake-php@googlegroups.com on behalf of majna
 Sent: Thu 6/28/2007 16:41
 To: Cake PHP
 Subject: Re: multiple line file import problem.

  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
-~--~~~~--~~--~--~---



RE: multiple line file import problem [solved]

2007-06-28 Thread Gould, Adrian

Thanks Geoff

it did have that in there at one point and did not work, then realised that the 
model had changed a little so removed the validation on a field that no longer 
needed to be filled and voila!

Thank you for all the help.

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
-~--~~~~--~~--~--~---