Created
November 24, 2011 22:16
-
-
Save mmhan/1392421 to your computer and use it in GitHub Desktop.
Editing multiple records with saveAll()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function edit() { | |
if(!empty($this->data)) { | |
$this->Profile->saveAll($this->data['Profile']); | |
} | |
else { | |
$this->data['Profile'] = Set::combine($this->Profile->find('all'), '{n}.Profile.id', '{n}.Profile'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Converting findAll() to saveAll() for editing multiple records. | |
* http://nuts-and-bolts-of-cakephp.com/2008/10/27/editing-multiple-records-with-saveall/ | |
**/ | |
/***** | |
* findAll() format | |
Array | |
( | |
[0] => Array | |
( | |
[Profile] => Array | |
( | |
[id] => 21 | |
[name] => bob 3 | |
[created] => 2008-10-27 13:01:30 | |
) | |
) | |
[1] => Array | |
( | |
[Profile] => Array | |
( | |
[id] => 20 | |
[name] => larry 5 | |
[created] => 2008-10-27 13:01:30 | |
) | |
) | |
) | |
**/ | |
/*** | |
* saveAll() format | |
[Profile] => Array | |
( | |
[21] => Array | |
( | |
[id] => 21 | |
[name] => bob 3 | |
[created] => 2008-10-27 13:01:30 | |
) | |
[20] => Array | |
( | |
[id] => 20 | |
[name] => larry 5 | |
[created] => 2008-10-27 13:01:30 | |
) | |
); | |
**/ | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo $form->create('Profile', array('action'=>'edit')); | |
foreach($this->data['Profile'] as $key => $value) { | |
echo $form->input('Profile.'.$key.'.name'); | |
echo $form->input('Profile.'.$key.'.id'); | |
} | |
echo $form->end('Save All Profiles'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment