开发者

edit multiple database rows in a symfony form

开发者 https://www.devze.com 2023-03-01 18:59 出处:网络
symfony created a dogform class which can edit one dog entry in the database. to display the form in the view i use currently:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号