1. Go to this page and download the library: Download pvsaintpe/ltree-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pvsaintpe / ltree-bundle example snippets
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\Entity;
use LTree\Annotation\LTreeChilds;
use LTree\Annotation\LTreeEntity;
use LTree\Annotation\LTreeParent;
use LTree\Annotation\LTreePath;
use LTree\Repository\LTreeEntityInterface;
/**
* Class TestEntity
* @package LTree\Entity
*
* @Entity(repositoryClass="LTree\Entity\TestRepository")
* @LTreeEntity()
*/
class TestEntity implements LTreeEntityInterface
{
/**
* @ORM\Id()
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
private $id;
/**
* @LTreePath()
* @ORM\Column(type="ltree")
*/
private $path = null;
/**
* @LTreeParent()
* @ORM\ManyToOne(targetEntity="TestEntity", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
*/
private $parent;
/**
* @LTreeChilds()
* @ORM\OneToMany(targetEntity="TestEntity", mappedBy="parent", cascade={"all"}, orphanRemoval=true)
* @ORM\JoinColumn(onDelete="CASCADE")
*/
private $children;
/**
* Constructor
*/
public function __construct()
{
$this->children = new ArrayCollection();
}
}