symfony - Type of choice field Symfony2 -


i try save values of 1 - 3 checkboxes in field category in database, error :

notice: array string conversion in /var/www/ontheway/vendor/doctrine/dbal/lib/doctrine/dbal/statement.php line 120 

the field:

 /**  * @orm\column(type="string", length=255, nullable=true)  */ private $category; 

get & set:

    /**  * @return mixed  */ public function getcategory() {     return $this->category; }  /**  * @param $category  */ public function setcategory($category) {     $this->category[] = $category; } 

profile type:

 namespace vputi\userbundle\form\type;  use symfony\component\form\abstracttype; use symfony\component\form\formbuilderinterface; use symfony\component\optionsresolver\optionsresolverinterface;  class profiletype extends  abstracttype {     public function buildform(formbuilderinterface $builder, array $options)     {         $builder->add('fio');         $builder->add('birthdate', null, array('widget' => 'single_text'));         $builder->add('file');         $builder->add('yearonroad');         $builder->add('telephone');         $builder->add('contactmail');         $builder->add('role', 'choice', array('choices' => array(1 => 'За рулем') ,'expanded'=>true, 'multiple' => true,));         $builder->add('category', 'choice', array(             'choices'  => array('a' => 'Категория А', 'b' => 'Категория b', 'c' => 'Категория c',),             'expanded' => true,             'multiple' => true,         ));     }     public function setdefaultoptions(optionsresolverinterface $resolver)     {         $resolver->setdefaults(array(             'data_class' =>'vputi\userbundle\entity\profile',             'cascade_validation' => true,         ));     }  } 

here form type, hope me, , iam ommit getname() method.

the problem $category defined string you're using array.

the solution depends on want accomplish. if want mapped array have this:

/**  * @orm\column(type="array", nullable=true)  */ private $category; 

when using doctrine's array type, make sure take account: how force doctrine update array type fields?


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -