symfony - How to list entity in form -
i have entity hall
can either welcome hall
(subhall), or stand
.
i'm stuck hall
form (or @ least it's think needs edited). can't figure out how have display <select>
of hall
parent=0
need default option blank 0
value
here files:
hall entity:
<?php namespace salonbundle\entity; use doctrine\orm\mapping orm; /** * hall * * @orm\table(name="hall") * @orm\entity(repositoryclass="salonbundle\repository\hallrepository") */ class hall { /** * @var int * * @orm\column(name="id", type="integer") * @orm\id * @orm\generatedvalue(strategy="auto") */ private $idhall; /** * @var string * @orm\column(name="name", type="string", length=255) */ private $name; /** * @var integer * @orm\column(name="parent", type="integer", options={"default":0}) */ private $parent; /** * @var * @orm\onetomany(targetentity="salonbundle\entity\stand", mappedby="hall") */ private $stand; public function __construct() { $this->stand = new \doctrine\common\collections\arraycollection(); } /** * idhall * @return integer */ public function getidhall() { return $this->idhall; } /** * set name * @param string $name * @return hall */ public function setname($name) { $this->name = $name; return $this; } /** * name * @return string */ public function getname() { return $this->name; } /** * set parent * @param integer $parent * @return hall */ public function setparent($parent) { $this->parent = $parent; return $this; } /** * parent * @return string */ public function getparent() { return $this->parent; } /** * add stand * @param \salonbundle\entity\stand $stand * @return hall */ public function addstand(\salonbundle\entity\stand $stand) { $this->stand[] = $stand; return $this; } /** * remove stand * @param \salonbundle\entity\stand $stand */ public function removestand(\salonbundle\entity\stand $stand) { $this->stand->removeelement($stand); } /** * stand * @return \doctrine\common\collections\collection */ public function getstand() { return $this->stand; } /** * tostring * @return string */ public function __tostring() { return $this->getname(); } }
hall form :
<?php namespace salonbundle\form; use salonbundle\entity\hall; use symfony\component\form\abstracttype; use symfony\component\form\formbuilderinterface; use symfony\component\optionsresolver\optionsresolver; class halltype extends abstracttype { /** * @param formbuilderinterface $builder * @param array $options */ public function buildform(formbuilderinterface $builder, array $options) { $builder ->add('name') ->add('parent') // need complete part ; } /** * @param optionsresolver $resolver */ public function configureoptions(optionsresolver $resolver) { $resolver->setdefaults(array( 'data_class' => 'salonbundle\entity\hall' )); } }
how should proceed ?
with 'query_builder' option can filter entities:
http://symfony.com/doc/current/reference/forms/types/entity.html#ref-form-entity-query-builder
$builder->add('users', entitytype::class, array( 'class' => 'appbundle:user', 'query_builder' => function (entityrepository $er) { return $er->createquerybuilder('u') ->orderby('u.username', 'asc'); }, 'choice_label' => 'username', ));
Comments
Post a Comment