我有一个包含媒体、文档、PDF 和文件夹列表的数据表格。像 Google Drive 一样,我想在数据表格顶部显示面包屑导航。通过 jQuery 点击任何文件夹时,数据表格会反映出更改。除了面包屑导航以外,一切都准备就绪。虽然我有当前打开文件夹的ID,但我不知道如何从根目录到当前文件夹获取层次结构。
目前它只提供了父 ID 和名称,而没有提供整个层次结构。
注意::列之间没有关系,因为它们在同一表中。
实体字段:id,nameDisplay,parentId
实体定义:
/**
* driveall
* @ORM\Table(name="Driveall")
* @ORM\Entity(repositoryClass="DriveBundle\Repository\DriveallRepository")
*/
class Driveall
{
/**
* @var int
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
* @ORM\Column(name="Name_Display", type="string", length=255)
*/
private $nameDisplay;
/**
* @var int
* @ORM\Column(name="ParentID", type="integer")
*/
private $parentID;
/**
* Get id
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set nameDisplay
* @param string $nameDisplay
* @return driveall
*/
public function setNameDisplay($nameDisplay)
{
$this->nameDisplay = $nameDisplay;
return $this;
}
/**
* Get nameDisplay
* @return string
*/
public function getNameDisplay()
{
return $this->nameDisplay;
}
/**
* Set parentID
* @param integer $parentID
* @return Driveall
*/
public function setParentID($parentID)
{
$this->parentID = $parentID;
return $this;
}
/**
* Get parentID
* @return integer
*/
public function getParentID()
{
return $this->parentID;
}
}
查询构建器:
$qb = $this->_em->createQueryBuilder();
$qb->select("d.parentID,pid.nameDisplay")
->from($this->_entityName, 'd')
->leftJoin($this->_entityName, 'pid', 'WITH', 'pid.id = d.parentID')
->where("d.status=0")
->andWhere("d.id=" . $id)
->orderBy('d.nameDisplay', 'ASC');
$data = $qb->getQuery()
->getResult();
return $data;