如何在下拉列表中选择一个值?
我有一个下拉列表,当我在编辑案例中填写下拉列表时,如何显示数据库中的选定值?
它是表单构建器类
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('name')
->add('description')
->add('parentid', 'entity', array('class'=>'MusicCoreBundle:MusicCategory',
'property' => 'name',
'required' => false,
'query_builder' => function(EntityRepository $er) {return $er->createQueryBuilder('s')->orderBy('s.name', 'ASC');},
'empty_value' => 'No category'));
}
这是用于 ER,我认为与 id 和 parentid 的实体关系是错误的,请用代码回复,在实体声明中:
/**
* Music\Bundles\Core\Entity\MusicCategory
* @ORM\Table(name="ms_musiccategory")
* @ORM\Entity()
* @ORM\Entity(repositoryClass="Music\Bundles\Core\Entity\Repository\CategoryRepository")
* @UniqueEntity(fields={"name"},message="The name is already in this system.")
*/
class MusicCategory
{
/**
* @ORM\Column(name="id",type="integer")
* @ORM\Id()
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
*@ORM\ManyToOne(targetEntity="MusicCategory")
*@ORM\JoinColumn(name="parent_Id", referencedColumnName="id")
*
*/
private $parentid;
/**
* @ORM\Column(name="name", type="string", length=50, unique=true)
*/
private $name;
/**
* @ORM\Column(name="description", type="string", length=200)
*/
private $description;
public function __construct()
{
}
/**
* @see RoleInterface
*/
public function getName()
{
return $this->name;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set id
*
* @return integer
*/
public function setId($id)
{
$this->id = $id;
}
/**
* Get parentid
*
* @return integer
*/
public function getParentId()
{
return $this->parentid;
}
/**
* Get parentid
*
* @return integer
*/
public function setParentId($parentid)
{ $this->parentid = $parentid;
}
/**
* Set role
*
* @param string $role
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Set description
*
* @param string $description
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
}
提前致谢。