dimanche 29 mars 2015

symfony form entity update

I'm trying to create a for with an entity.


My controller:



$questionnaire = $em->getRepository('questionnaireBundle:questionnaire')->findOneBy(array('id' => $id));

$form = $this->createForm(new questionnaireType(), $questionnaire);


QuestionnaireType:



public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('nom', 'text', array('label' => 'Nom:'));
$builder->add('nbreQuestions', 'text', array('label' => 'Nombre de questions:'));
$builder->add('type', 'entity', array('class' => 'questionnaireBundle:type', 'property' => 'type'));
$builder->add('envoyer', 'submit', array('label' => 'Enregistrer', 'attr' => array('class' => 'btn btn-success col-md-12')));
}


The entity: questionnaire



namespace questionnaireBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
* questionnaire
*
* @ORM\Table()
* @ORM\Entity
*/
class questionnaire {

/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;

/**
* @var string
*
* @ORM\Column(name="nom", type="string", length=255)
*/
private $nom;
/**
* @var string
*
* @ORM\Column(name="type", type="string", length=255)
*/
private $type;

/**
* @var integer
*
* @ORM\Column(name="nbreQuestions", type="integer")
*
* @Assert\NotBlank(message="Veuillez entrer un nombre de questions.")
* @Assert\Type(type="integer")
*/
private $nbreQuestions;

/**
* Get id
*
* @return integer
*/
public function getId() {
return $this->id;
}

/**
* Set nom
*
* @param string $nom
* @return questionnaire
*/
public function setNom($nom) {
$this->nom = $nom;

return $this;
}

/**
* Get nom
*
* @return string
*/
public function getNom() {
return $this->nom;
}
/**
* Set type
*
* @param string $type
* @return type
*/
public function setType($type) {
$this->type = $type;

return $this;
}

/**
* Get type
*
* @return string
*/
public function getType() {
return $this->type;
}

/**
* Set nbreQuestions
*
* @param integer $nbreQuestions
* @return questionnaire
*/
public function setNbreQuestions($nbreQuestions) {
$this->nbreQuestions = $nbreQuestions;

return $this;
}

/**
* Get nbreQuestions
*
* @return integer
*/
public function getNbreQuestions() {
return $this->nbreQuestions;
}

public function __toString() {
return (string) $this->getNom();
}

}


The field nom, nbreQuestions will automatically be fully with the entity questionnaire, but type is not update!


Anybody knows why?


Thanks Best regards


Aucun commentaire:

Enregistrer un commentaire