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

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -