PHP code example of clear01 / doctrine-extensions-tree

1. Go to this page and download the library: Download clear01/doctrine-extensions-tree 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/ */

    

clear01 / doctrine-extensions-tree example snippets


namespace App\Entities;

use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;


/**
 * @ORM\Entity(repositoryClass="App\Model\CategoryTree")
 * @Gedmo\Tree(type="materializedPath")
 */
class Category
{

	/**
	 * @ORM\Column(type="integer")
	 * @ORM\Id
	 * @ORM\GeneratedValue
	 */
	public $id;

	/**
	 * @Gedmo\TreePathSource
	 * @ORM\Column(type="string")
	 * @var string
	 */
	private $name;

	/**
	 * @Gedmo\TreeParent
	 * @ORM\ManyToOne(targetEntity="Category", cascade={"persist"})
	 * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", nullable=TRUE)
	 * @var Category
	 */
	private $parent;

	/**
 	 * @Gedmo\TreePath(separator="|")
	 * @ORM\Column(type="string", nullable=TRUE)
	 * @var string
	 */
	private $path;


	/**
	 * @param string $name
	 * @param Category $parent
	 */
	public function __construct($name, Category $parent = NULL)
	{
		$this->name = $name;
		$this->parent = $parent;
	}


	/**
	 * @return string
	 */
	public function getName()
	{
		return $this->name;
	}


	/**
	 * @return Category
	 */
	public function getParent()
	{
		return $this->parent;
	}


	/**
	 * @return string
	 */
	public function getPath()
	{
		return $this->path;
	}

}

namespace App\Model;

use Gedmo\Tree\Entity\Repository\MaterializedPathRepository;


class CategoryTree extends MaterializedPathRepository
{

}