database - Symfony 2 override entity field property -


i want override entity field property. need data database table (mapped id). should combination of "artikelnummer" , field called "name" database table.

$builder->add('schlauch', 'entity', array(     'class' => 'schlauchbundle:artikelspezifikation',     'property' => 'artikelnummer',     'attr' => array(       'class' => 'extended-select'      ),      'data_class' => null     )); 

the field "artikelnummer" outputs "12345" need add name (from database table called "schlauch"), should "12345 articlename". tried query in entity file, dont't want manipulate output everywhere.

is possible use query property , override it?

you can simple solve adding new getter entity:

class artikelspezifikation {     //…      /**      * @var schlauch      *      * @orm\manytoone(targetentity="schlauch", inversedby="artikelspezifikations")      */     private $schlauch;      //…      /**      * display name      *       * @return string      */     public function getdisplayname()     {         return $this->artikelnummer . ' ' . $this->schlauch->getartikelname();     }      //…      /**      * set schlauch      *      * @param \schlauchbundle\entity\schlauch $schlauch      *      * @return artikelspezifikation      */     public function setcategory(\schlauchbundle\entity\schlauch $schlauch = null)     {         $this->schlauch = $schlauch;          return $this;     }      /**      * schlauch      *      * @return \schlauchbundle\entity\schlauch      */     public function getcategory()     {         return $this->schlauch;     } } 

and in form class change property:

$builder->add('schlauch', 'entity', array(     'class' => 'schlauchbundle:artikelspezifikation',     'property' => 'displayname',     'attr' => array(       'class' => 'extended-select'      ),      'data_class' => null     )); 

Comments

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -