내 범주 옵션 목록에 대한 트리 구조를 만들어야합니다. 옵션 목록에 대한 나의 폼 타입 코드 :드롭 다운 옵션 구조
->add('discipline', 'entity', array('label' => 'Parent Discipline',
'empty_value' => 'Parent Discipline...',
'required' => true,
'empty_data' => null,
'class' => 'RFQ\IronilBundle\Entity\ProductionType',
'query_builder' => function(ProductionTypeRFQRepository $er) {return $er->createQueryBuilder('w')->where('w.parent IS NULL')->addOrderBy('w.name', 'ASC');},
'attr' => array('class'=>'form-control login-input')))
당신은 내가 트리 구조의 데이터베이스에서 옵션 목록을 얻을 것이다 저장소를 연결했지만, 나는 그 작업을 수행하는 방법을 정확히 모르는 볼 수 있듯이. 이제 내 저장소는 다음과 같습니다.
<?php
namespace RFQ\IronilBundle\Entity;
use Doctrine\ORM\EntityRepository;
class ProductionTypeRFQRepository extends EntityRepository
{
public function findAllParents()
{
return $this->getEntityManager()
->createQuery('SELECT p FROM RFQIronilBundle:ProductionType p WHERE p.parent IS NULL ORDER BY p.name ASC')
->getResult();
}
public function findAll()
{
return $this->findBy(array(), array('name' => 'ASC'));
}
}
이 저장소는 부모 만 가져 오지만 데이터베이스의 하위는 가져 오지 않습니다.
여기에 대한 해결책을 찾을 수있는 정보를 제공해주십시오.
편집 : 요청에 대한
,이 범주에 대한 내 엔티티이다 : 나는 (나는 모든 항목을 삭제 한 범주이 트리 구조를 필요로하는 내 RFQ에 대한
<?php
namespace RFQ\IronilBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* ProductionType
*
* @ORM\Table(name="production_type")
* @ORM\Entity(repositoryClass="RFQ\IronilBundle\Entity\ProductionTypeRepository")
* @ORM\Entity(repositoryClass="RFQ\IronilBundle\Entity\ProductionTypeRFQRepository")
*/
class ProductionType
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string")
* @ORM\OneToMany(targetEntity="RFQ", mappedBy="discipline")
*/
protected $name;
/**
* @ORM\OneToMany(targetEntity="ProductionType", mappedBy="parent")
* @ORM\OrderBy({"name" = "ASC"})
**/
protected $children;
/**
* @ORM\ManyToOne(targetEntity="ProductionType", inversedBy="children")
**/
protected $parent;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Constructor
*/
public function __construct()
{
$this->children = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Set name
*
* @param string $name
* @return ProductionType
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Add children
*
* @param \RFQ\IronilBundle\Entity\ProductionType $children
* @return ProductionType
*/
public function addChild(\RFQ\IronilBundle\Entity\ProductionType $children)
{
$this->children[] = $children;
return $this;
}
/**
* Remove children
*
* @param \RFQ\IronilBundle\Entity\ProductionType $children
*/
public function removeChild(\RFQ\IronilBundle\Entity\ProductionType $children)
{
$this->children->removeElement($children);
}
/**
* Get children
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getChildren()
{
return $this->children;
}
/**
* Set parent
*
* @param \RFQ\IronilBundle\Entity\ProductionType $parent
* @return ProductionType
*/
public function setParent(\RFQ\IronilBundle\Entity\ProductionType $parent = null)
{
$this->parent = $parent;
return $this;
}
/**
* Get parent
*
* @return \RFQ\IronilBundle\Entity\ProductionType
*/
public function getParent()
{
return $this->parent;
}
public function __toString()
{
return $this->name;
}
}
그리고 실체가있는 문제를 해결할 필요가 없음) :
엔티티를 붙여 넣을 수 있습니까? –