He creado la entidad siguiendo esta documentacion y en la DB se crean bien los registros, pero cuando voy a listarlos, me sale una lista normal y lo que busco es hacer algo asi:
Código HTML:
<table> <tr> <td>Category-1 name</td> <td>Category-1 other data</td> </tr> <tr> <td>Category-2 name</td> <td>Category-2 other data</td> </tr> <tr> <td><span class="indent">---</span>Subcategory-2-1 name</td> <td>Subcategory-2-1 other data</td> </tr> <tr> <td><span class="indent">---</span><span class="indent">---</span>Subcategory-2-1-1 name</td> <td>Subcategory-2-1-1 other data</td> </tr> <tr> <td>Category-3 name</td> <td>Category-3 other data</td> </tr> </table>
Actualmente este es mi controlador de listado:
Código PHP:
public function categoriesAction()
{
$em = $this->getDoctrine()->getEntityManager();
$categories = $em->createQuery("SELECT c FROM AcmeBundle:Category c");
$default_items = $this->container->getParameter('paginator_items');
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$categories,
$this->get('request')->query->get('page', 1),
$this->get('request')->query->get('max', $default_items[0]));
return $this->render('Acme:Category:list.html.twig', array(
'pagination' => $pagination
));
}
Código PHP:
<?php
namespace AcmeDemoBundleEntity;
use DoctrineORMMapping as ORM;
use GedmoMappingAnnotation as Gedmo;
use GedmoTranslatableTranslatable;
/**
* @Gedmo\Tree(type="nested")
* @ORM\Table(name="category")
* @ORM\Entity(repositoryClass="Acme\DemoBundle\Entity\CategoryRepository")
*/
class Category
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @Gedmo\Locale
*/
private $locale;
/**
* @var string
*
* @Gedmo\Translatable
* @ORM\Column(name="name_es", type="string", length=100)
*/
private $name;
/**
* @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="Category", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $parent;
/**
* @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
* @ORM\OrderBy({"lft" = "ASC"})
*/
private $children;
/**
* @ORM\Column(name="meta_description", type="text", nullable=true)
*/
private $metaDescription;
/**
* @ORM\Column(name="meta_keywords", type="array", nullable=true)
*/
private $metaKeywords;
}