edit multiple database rows in a symfony form
symfony created a dogform class which can edit one dog entry in the database. to display the form in the view i use currently:
<?php echo $form; ?>
well now i want to edit multiple dogs at once (in one page). how do i do this? i think i need the same form multiple times but with different initia开发者_如何学编程l data (dogs)
You need one form, because you can only submit one form at a time, according to html spec. This form will embed a collection of DogForm.
class DogCollectionForm extends sfForm
{
$dogs = Doctrine::getTable('Dog')->findAll();
foreach ($dogs as $i => $dog)
{
$dogForm = new DogForm($dog);
$this->embedForm($i, $dogForm);
}
}
As an enhancement, pass $dogs to form from action as a parameter.
精彩评论