我想选择其他字段显示在我的表单复选框。如何在'选项'findall后选择表单的显示区域?
我的实体Filter
有三个属性id
,name
和subtitle
。
我的代码显示我的name
值,如何显示subtitle
值?
我FormBuilder(控制器):
$formFilter = $this->createFormBuilder()
->add('_', ChoiceType::class,array(
'choices' => $this->getDoctrine()->getManager()->getRepository('loicFilterBundle:Filter')->findAll(),
'multiple' => true,
'expanded' => true,
'choice_label' => function($value, $key, $index) {
return ($value);
},
))
->add('Appliquer filtres', SubmitType::class)
->getForm();
筛选:
namespace loic\FilterBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Filter
*
* * @ORM\Entity(repositoryClass="loic\FilterBundle\Entity\FilterRepository")
* @ORM\Table(name="filter", uniqueConstraints={@ORM\UniqueConstraint(name="idfilter_UNIQUE", columns={"idfilter"})}, indexes={@ORM\Index(name="fk_filter_filter_category1_idx", columns={"filter_category_idfilter_category"})})
*/
class Filter
{
/**
* @var integer
*
* @ORM\Column(name="idfilter", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $idfilter;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=45, nullable=true)
*/
private $name;
/**
* @var \FilterCategory
*
* @ORM\ManyToOne(targetEntity="FilterCategory")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="filter_category_idfilter_category", referencedColumnName="idfilter_category")
* })
*/
private $filterCategoryfilterCategory;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="loic\ContentBundle\Entity\Content", mappedBy="filterfilter")
*/
private $contentcontent;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="loic\UserBundle\Entity\User", mappedBy="filterfilter")
*/
private $user;
/**
* @var string
*
* @ORM\Column(name="subtitle", type="string", length=45, nullable=true)
*/
private $subtitle;
/**
* @var string
*
* @ORM\Column(name="description", type="string", length=45, nullable=true)
*/
private $description;
/**
* @var string
*
* @ORM\Column(name="status", type="string", length=45, nullable=false)
*/
private $status;
/**
* Constructor
*/
public function __construct()
{
$this->contentcontent = new \Doctrine\Common\Collections\ArrayCollection();
$this->user = new \Doctrine\Common\Collections\ArrayCollection();
$this->status = 1;
}
/**
*
* @return the integer
*/
public function getIdfilter() {
return $this->idfilter;
}
/**
*
* @param
* $idfilter
*/
public function setIdfilter($idfilter) {
$this->idfilter = $idfilter;
return $this;
}
/**
*
* @return the string
*/
public function getName() {
return $this->name;
}
/**
*
* @param
* $name
*/
public function setName($name) {
$this->name = $name;
return $this;
}
/**
*
* @return the \FilterCategory
*/
public function getFilterCategoryfilterCategory() {
return $this->filterCategoryfilterCategory;
}
/**
*
* @param \FilterCategory $filterCategoryfilterCategory
*/
public function setFilterCategoryfilterCategory($filterCategoryfilterCategory) {
$this->filterCategoryfilterCategory = $filterCategoryfilterCategory;
return $this;
}
/**
*
* @return the \Doctrine\Common\Collections\Collection
*/
public function getContentcontent() {
return $this->contentcontent;
}
/**
*
* @param
* $contentcontent
*/
public function setContentcontent($contentcontent) {
$this->contentcontent = $contentcontent;
return $this;
}
public function __toString(){
return $this->name;
}
/**
*
* @return the \Doctrine\Common\Collections\Collection
*/
public function getUser() {
return $this->user;
}
/**
*
* @param
* $user
*/
public function setUser($user) {
$this->user = $user;
return $this;
}
/**
*
* @return the string
*/
public function getSubtitle() {
return $this->subtitle;
}
/**
*
* @param
* $subtitle
*/
public function setSubtitle($subtitle) {
$this->subtitle = $subtitle;
return $this;
}
/**
*
* @return the string
*/
public function getDescription() {
return $this->description;
}
/**
*
* @param
* $description
*/
public function setDescription($description) {
$this->description = $description;
return $this;
}
/**
*
* @return the string
*/
public function getStatus() {
return $this->status;
}
/**
*
* @param
* $status
*/
public function setStatus($status) {
$this->status = $status;
return $this;
}
}
你能过去你的过滤器型号代码吗? – Alex
为什么你应该通过“setUser”分配$ user? ... $ this-> user = new \ Doctrine \ Common \ Collections \ ArrayCollection(); ... 它是数据库实体还是字段名? – Alex