I have this function in a CategoryBundle:CategoryTreeBuilderController
:
/**
* Get subcategories based on $parent_id parameter
*
* @Route("/category/tree/{parent_id}", name="category_tree", options={"expose"=true})
* @Method("GET")
*/
public function BuildCategoryTree($parent_id = null) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('CategoryBundle:Category')->findBy(array("parent" => $parent_id));
if (!$entity) {
throw $this->createNotFoundException('Unable to find Category entity.');
}
return $this->render("CategoryBundle:Default:index.html.twig", array('entities' => $entity));
}
I need to call this function recursively from my Twig template so every times the parent has children a kind of indentation occurs. I'm trying to implement a Tree behavior. I check this post but is not helpful at all, can any guide me on the right path?