<?php
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
/**
* @Gedmo\Tree(type="nested")
* @ORM\Table(name="Tree")
* @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository")
*/
class Tree
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue
*/
private $id;
/**
* @Gedmo\TreeLeft
* @ORM\Column(name="lft", type="integer")
*/
private $lft;
/**
* @Gedmo\TreeLevel
* @ORM\Column(name="lvl", type="integer")
*/
private $lvl;
/**
* @Gedmo\TreeRight
* @ORM\Column(name="rgt", type="integer")
*/
private $rgt;
/**
* @Gedmo\TreeRoot
* @ORM\Column(name="root", type="integer", nullable=true)
*/
private $root;
/**
* @Gedmo\TreeParent
* @ORM\ManyToOne(targetEntity="Tree", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $parent;
/**
* @ORM\OneToMany(targetEntity="Tree", mappedBy="parent")
* @ORM\OrderBy({"lft" = "ASC"})
*/
private $children;
}
{
"require": {
"doctrine/orm": "2.5.0"
},
"autoload": {
"psr-4": {
"": "src/"
},
"psr-0": { "Gedmo\\": "lib/" }
}
}
composer dump-autoload
$treeListener = new Gedmo\Tree\TreeListener();
$entityManager->getEventManager()->addEventSubscriber($treeListener);
<?php
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
/**
* @Gedmo\Tree(type="nested")
* @ORM\Table(name="Tree")
* @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository")
*/
class Tree {
/**
* @ORM\Id @ORM\GeneratedValue @ORM\Column(type="integer")
*
* @var int
*/
private $id;
public function getId() {
return $this->id;
}
}