0
votes

I am trying to create a form Houses and embed the Images forms into it. I have follow the tutorial http://www.symfony-project.org/more-with-symfony/1_4/en/06-Advanced-Forms.

I have the following schema:

houses:
  actAs: { Timestampable: ~ }
  columns:
    name: { type: string(255), notnull: true }
    description: { type: string(5000), notnull: true }

images:
  actAs: { Timestampable: ~ }
  columns:
    url: { type: string(255), notnull: true }
    id_house: { type: integer, notnull: true }
    relations:
    houses: { local: id_house, foreign: id, foreignAlias: HousesImg}

and the code :

//lib/form/doctrine/ImagesCollectionForm

class ImagesCollectionForm extends sfForm
{
  public function configure()
  {
    if(!$house= $this->getOption('house'))
    {
      throw new InvalidArgumentException('You must provide an house');
    }

    for ($i = 0; $i < $this->getOption('size',2); $i++)
    {
      $images = new images();
      $images->house = $house;

      $form = new imagesForm($images);
      $this->embedForm($i, $form);
    }
  }
}

//lib/form/doctrine/housesForm.class.php

public function configure()
{
  $form = new ImagesCollectionForm(null, array('house' => $this->getObject(),'size'=>2));
  $this->embedForm('images', $form);
}

The fields are displayed as expected. But, when I press the save button I get a blank page and the data aren't saved in database.

1
Did you try using the dev crontroler (frontend_dev.php) to see errors?j0k
don't you have a typo? $images->house = $house; for $images->houses = $house;Visavì
I found the problem. In the imagesForm.class.php I didn't add $this->useFields(...), and there was a problem with house_id field. Now it's working.july
Anyway, thank you for your replayjuly

1 Answers

0
votes

use have not specified alias in Images relation with product so by default symfony look it for relation name

so u need to change $images->house = $house; to $images->houses = $house; or u can set alias in relation

hope this will help.