symfony - Form with entity field, saved in database rare string -


i've form:

<?php namespace feb\twitterbundle\form; use symfony\component\form\abstracttype; use symfony\component\form\formbuilderinterface; class twitterposttype extends abstracttype {     public function buildform(formbuilderinterface $builder, array $options)     {         $builder->add('titulo')                 ->add('tweet', 'textarea')                 ->add('photo', 'file', array('required' => false))                               ->add('tags', 'entity', array(                                                 'class' =>    'febtagsbundle:tag',                                                 'property' => 'tag',                                                 'empty_value' => 'selecciona tags',                                                 'multiple' => true));                    }     public function getname()     {         return 'twitter_form';     } } 

when save in database, field "tag" save string:

doctrine\common\collections\arraycollection@000000000b3d932100000000287ad87a 

and not value of property "tag", mistake? or conversely, that's right , have show in twig template correctle formatted?

thank in advance.

edit1:

solution: finally, have had modified twitterpost entity:

<?php  namespace feb\twitterbundle\entity;  use doctrine\orm\mapping orm; use symfony\component\validator\constraints assert; use doctrine\common\collections\arraycollection;  /**  * twitterpost  *  * @orm\table()  * @orm\entity(repositoryclass="feb\twitterbundle\entity\twitterpostrepository")  */ class twitterpost {     /**      * @var integer      *      * @orm\column(name="id", type="integer")      * @orm\id      * @orm\generatedvalue(strategy="auto")      */     private $id;      /**      * @var string      *      * @orm\column(name="titulo", type="string", length=50)      * @assert\notnull(message="debe escribir un titulo")      */     private $titulo;      /**      * @var string      *      * @orm\column(name="tweet", type="string", length=145)      * @assert\notnull(message="debe escribir un tweet")      */     private $tweet;     /**    * many-to-many, unidirectional    *    * @var arraycollection $tags    *    * @orm\manytomany(targetentity="\feb\tagsbundle\entity\tag")    * @orm\jointable(name="twitter_has_tag",    *      joincolumns={@orm\joincolumn(name="twitter_id", referencedcolumnname="id")},    *      inversejoincolumns={@orm\joincolumn(name="tag_id", referencedcolumnname="id")}    * )    */     private $tags;        public function __construct()    {     $this->tags = new arraycollection();    }       /**      * id      *      * @return integer       */     public function getid()     {         return $this->id;     }      /**      * set titulo      *      * @param string $titulo      * @return twitterpost      */     public function settitulo($titulo)     {         $this->titulo = $titulo;          return $this;     }      /**      * titulo      *      * @return string       */     public function gettitulo()     {         return $this->titulo;     }      /**      * set tweet      *      * @param string $tweet      * @return twitterpost      */     public function settweet($tweet)     {         $this->tweet = $tweet;          return $this;     }      /**      * tweet      *      * @return string       */     public function gettweet()     {         return $this->tweet;     }      /**      * set tags      *      * @param string $tags      * @return twitterpost      */     public function settags($tags)     {         $this->tags = $tags;          return $this;     }      /**      * tags      *      * @return string       */     public function gettags()     {         return $this->tags;     }    } 

the entity tag has no change.

that changes generate next database table:
table: twitter_has_tag
twitter_id
tag_id

i think it's right, no?

you need manytomany relationship between twitterposts , tags entity.

you need put twitterposts entity:

/**  * @orm\manytomany(targetentity="tags", inversedby="twitterposts")  * @orm\jointable(name="twitterpost_tags",  *   joincolumns={@orm\joincolumn(name="twitterpost_id", referencedcolumnname="id")},  *   inversejoincolumns={@orm\joincolumn(name="tag_id", referencedcolumnname="id")}  * )  */ private $tags; 

and arraycollection:

public function __construct() {     $this->tags = new arraycollection(); } 

make getter , setter element , other side in tags entity.

here doctrine documentation: http://docs.doctrine-project.org/en/2.0.x/reference/association-mapping.html#many-to-many-unidirectional


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -