i have a simple probleme but i dont know how to fix it,
Here we go,
I already have a table that contains all menu registred on database, like this
http://snapplr.com/snap/hbch
But, the entity with title A is parent of entity B, so all i want to do now is to tree my list as dependencies with parent and children Tree Gedmo annotation.
this is my index.html.twig page
{% block tbody %}
{% for entity in entities %}
<tr>
<td>{{ entity.title|title }}</td>
<td>{% if entity.type == 'javascript:void(0)' %}
Groupe
{% else %}
{{ entity.type|title }}
{% endif %}</td>
<td>{{ entity.value|title }}</td>
<td>
{% render(controller('MenuBundle:Backend/MenuExtends:createDelete', {'id' : entity.id, 'menu' : id})) %}
</td>
</tr>
{% endfor %}
{% endblock %}
Ok
here my entity
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="Menu", inversedBy="extends")
*/
private $menu;
/**
* #var string
* #Gedmo\TreePathSource
* #ORM\Column(name="type", type="string", length=255, nullable=false)
*/
private $type;
/**
* #var string
* #ORM\Column(name="value", type="string", length=255, nullable=false)
*/
private $value;
/**
* #Gedmo\TreeLeft
* #ORM\Column(name="submenu_left", type="integer")
*/
private $lft;
/**
* #Gedmo\TreeRoot
* #ORM\Column(name="submenu_root", type="integer", nullable=true)
*/
private $root;
/**
* #Gedmo\TreeLevel
* #ORM\Column(name="submenu_level", type="integer")
*/
private $lvl;
/**
* #Gedmo\TreeRight
* #ORM\Column(name="submenu_right", type="integer")
*/
private $rgt;
/**
* #Gedmo\TreeParent
* #ORM\ManyToOne(targetEntity="MenuExtends", inversedBy="children")
* #ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $parent;
/**
* #ORM\OneToMany(targetEntity="MenuExtends", mappedBy="parent")
* #ORM\OrderBy({"lft" = "ASC"})
*/
private $children;
what i want to do is :
if an entity have a children, in the same line , open x lines for the x children ...
Related
I have two entities, Customers and Locations. They are in a ManyToOne relationship (one customer can have multiple locations).
This is how I defined the relationship:
class Customers {
/**
* #ORM\Column(type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\Column(type="string", length=45)
*/
private $name;
}
And the entity Locations:
class Locations {
/**
* #ORM\Column(type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="Customers", inversedBy="id")
* #ORM\JoinColumn(name="customers_id", referencedColumnName="id")
*/
private $customers_id;
/**
* #ORM\Column(type="string", length=90)
*/
private $name;
}
I want to be able to click on a User and render in a Twig template all the locations associated to him. This is how I'm doing that now, but I'm not sure it's the proper way.
First the controller:
/**
* #Route("/showLocations/{id}", name = "show_locations")
* #Method("GET")
**/
public function showLocationsAction($id) {
$repository = $this->getDoctrine()->getRepository('AppBundle:Locations');
$locations = $repository->findBy(array('customer_id' => $id ));
$repository = $this->getDoctrine()->getRepository('AppBundle:Customers');
$customer = $repository->findOneById($id);
if(!empty($locations)) {
return $this->render("AppBundle:Default:showLocations.html.twig", array('locations' => $locations, 'customer' => $customer)); }
else return new Response ("There are no locations to show");
}
This is the twig template:
<p>Locations associated with {{customer.name}}</p>
<table id="table_id" class="display">
<thead>
<tr>
<th>Locations</th>
</tr>
</thead>
<tbody>
{% for locations in locations %}
<tr>
<td>{{ locations.name|e }}</td>
</tr>
{% endfor %}
</tbody>
Any suggestion? Thanks!
Looks fine so far. But naming for $customers_id should be $customer only since Doctrine will automatically fetch the related customer and hydrate it into an object.
Then you can fetch and display the customer with {{ location.customer.name }}
$repository = $this->getDoctrine()->getRepository('AtlasBundle:Customers');
$customer = $repository->findOneById($id);
Can be omitted totally then.
here again, I have a problem. I am developing an application with an entity of about 3600 records, when I display the index.html.twig which is a list of products takes too long, about 20 sec to show the bootstrap table.
My entity:
<?php
namespace Nival\InventarioBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* InProducto
*
* #ORM\Table(name="in_producto")
* #ORM\Entity
*/
class InProducto
{
/**
* #ORM\OneToMany(targetEntity="InProveedorProducto", mappedBy="InProducto", cascade={"persist"})
*/
protected $producto;
/**
* #ORM\OneToMany(targetEntity="InOrdenCompraDetalle", mappedBy="InProducto", cascade={"persist"})
*/
protected $productoOc;
public function __construct()
{
$this->producto = new ArrayCollection();
$this->productoOc = new ArrayCollection();
}
public function __toString() {
return $this->nombre;
}
/**
* #ORM\ManyToOne(targetEntity="InSubLinea", inversedBy="InProducto")
* #ORM\JoinColumn(name="id_sub_linea", referencedColumnName="id")
*/
protected $subLinea;
/**
* #ORM\ManyToOne(targetEntity="InUnidadMedida", inversedBy="InProducto")
* #ORM\JoinColumn(name="id_unidad_medida", referencedColumnName="id")
*/
protected $unidadMedida;
public function getDisplayName()
{
return sprintf('%s (%s)', $this->nombre, $this->unidadMedida);
}
/**
* #var integer
*
* #ORM\Column(name="id_producto", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $idProducto;
/**
* #var string
*
* #ORM\Column(name="nombre", type="string", length=100, nullable=false)
*/
private $nombre;
/**
* #var string
*
* #ORM\Column(name="descripcion", type="string", length=100, nullable=true)
*/
private $descripcion;
/**
* #var integer
*
* #ORM\Column(name="id_unidad_medida", type="integer", nullable=false)
*/
private $idUnidadMedida;
/**
* #var string
*
* #ORM\Column(name="costo_promedio", type="decimal", precision=9, scale=6, nullable=false)
*/
private $costoPromedio;
/**
* #var integer
*
* #ORM\Column(name="id_sub_linea", type="integer", nullable=false)
*/
private $idSubLinea;
/**
* #var integer
*
* #ORM\Column(name="id_tipo_producto", type="integer", nullable=false)
*/
private $idTipoProducto;
/**
* #var \DateTime
*
* #ORM\Column(name="fecha_ingreso", type="date", nullable=false)
*/
private $fechaIngreso;
/**
* #var string
*
* #ORM\Column(name="precio1", type="decimal", precision=9, scale=2, nullable=false)
*/
private $precio1;
/**
* #var string
*
* #ORM\Column(name="precio2", type="decimal", precision=9, scale=2, nullable=false)
*/
private $precio2;
/**
* #var string
*
* #ORM\Column(name="precio3", type="decimal", precision=9, scale=2, nullable=false)
*/
private $precio3;
/**
* #var boolean
*
* #ORM\Column(name="inventariable", type="boolean", nullable=false)
*/
private $inventariable;
/**
* #var boolean
*
* #ORM\Column(name="facturable", type="boolean", nullable=false)
*/
private $facturable;
/**
* #var boolean
*
* #ORM\Column(name="activo", type="boolean", nullable=false)
*/
private $activo;
/**
* #var integer
*
* #ORM\Column(name="id_empresaa", type="integer", nullable=false)
*/
private $idEmpresaa;
/**
* Get idProducto
*
* #return integer
*/
public function getIdProducto()
{
return $this->idProducto;
}
/**
* Set nombre
*
* #param string $nombre
* #return InProducto
*/
public function setNombre($nombre)
{
$this->nombre = $nombre;
return $this;
}
/**
* Get nombre
*
* #return string
*/
public function getNombre()
{
return $this->nombre;
}
/**
* Set descripcion
*
* #param string $descripcion
* #return InProducto
*/
public function setDescripcion($descripcion)
{
$this->descripcion = $descripcion;
return $this;
}
/**
* Get descripcion
*
* #return string
*/
public function getDescripcion()
{
return $this->descripcion;
}
/**
* Set idUnidadMedida
*
* #param integer $idUnidadMedida
* #return InProducto
*/
public function setIdUnidadMedida($idUnidadMedida)
{
$this->idUnidadMedida = $idUnidadMedida;
return $this;
}
/**
* Get idUnidadMedida
*
* #return integer
*/
public function getIdUnidadMedida()
{
return $this->idUnidadMedida;
}
/**
* Set costoPromedio
*
* #param string $costoPromedio
* #return InProducto
*/
public function setCostoPromedio($costoPromedio)
{
$this->costoPromedio = $costoPromedio;
return $this;
}
/**
* Get costoPromedio
*
* #return string
*/
public function getCostoPromedio()
{
return $this->costoPromedio;
}
/**
* Set idSubLinea
*
* #param integer $idSubLinea
* #return InProducto
*/
public function setIdSubLinea($idSubLinea)
{
$this->idSubLinea = $idSubLinea;
return $this;
}
/**
* Get idSubLinea
*
* #return integer
*/
public function getIdSubLinea()
{
return $this->idSubLinea;
}
/**
* Set idTipoProducto
*
* #param integer $idTipoProducto
* #return InProducto
*/
public function setIdTipoProducto($idTipoProducto)
{
$this->idTipoProducto = $idTipoProducto;
return $this;
}
/**
* Get idTipoProducto
*
* #return integer
*/
public function getIdTipoProducto()
{
return $this->idTipoProducto;
}
/**
* Set fechaIngreso
*
* #param \DateTime $fechaIngreso
* #return InProducto
*/
public function setFechaIngreso($fechaIngreso)
{
$this->fechaIngreso = $fechaIngreso;
return $this;
}
/**
* Get fechaIngreso
*
* #return \DateTime
*/
public function getFechaIngreso()
{
return $this->fechaIngreso;
}
/**
* Set precio1
*
* #param string $precio1
* #return InProducto
*/
public function setPrecio1($precio1)
{
$this->precio1 = $precio1;
return $this;
}
/**
* Get precio1
*
* #return string
*/
public function getPrecio1()
{
return $this->precio1;
}
/**
* Set precio2
*
* #param string $precio2
* #return InProducto
*/
public function setPrecio2($precio2)
{
$this->precio2 = $precio2;
return $this;
}
/**
* Get precio2
*
* #return string
*/
public function getPrecio2()
{
return $this->precio2;
}
/**
* Set precio3
*
* #param string $precio3
* #return InProducto
*/
public function setPrecio3($precio3)
{
$this->precio3 = $precio3;
return $this;
}
/**
* Get precio3
*
* #return string
*/
public function getPrecio3()
{
return $this->precio3;
}
/**
* Set inventariable
*
* #param boolean $inventariable
* #return InProducto
*/
public function setInventariable($inventariable)
{
$this->inventariable = $inventariable;
return $this;
}
/**
* Get inventariable
*
* #return boolean
*/
public function getInventariable()
{
return $this->inventariable;
}
/**
* Set facturable
*
* #param boolean $facturable
* #return InProducto
*/
public function setFacturable($facturable)
{
$this->facturable = $facturable;
return $this;
}
/**
* Get facturable
*
* #return boolean
*/
public function getFacturable()
{
return $this->facturable;
}
/**
* Set activo
*
* #param boolean $activo
* #return InProducto
*/
public function setActivo($activo)
{
$this->activo = $activo;
return $this;
}
/**
* Get activo
*
* #return boolean
*/
public function getActivo()
{
return $this->activo;
}
public function setUnidadMedida($unidadMedida)
{
$this->unidadMedida = $unidadMedida;
return $this;
}
/**
* Get unidadMedida
*
* #return integer
*/
public function getUnidadMedida()
{
return $this->unidadMedida;
}
public function setSubLinea($subLinea)
{
$this->subLinea = $subLinea;
return $this;
}
/**
* Get subLinea
*
* #return integer
*/
public function getSubLinea()
{
return $this->subLinea;
}
public function setProducto($producto)
{
$this->producto = $producto;
return $this;
}
/**
* Get producto
*
* #return integer
*/
public function getProducto()
{
return $this->producto;
}
public function setProductoOc($productoOc)
{
$this->productoOc = $productoOc;
return $this;
}
/**
* Get productoOc
*
* #return integer
*/
public function getProductoOc()
{
return $this->productoOc;
}
/**
* Set idEmpresaa
*
* #param integer $idEmpresaa
* #return InProducto
*/
public function setIdEmpresaa($idEmpresaa)
{
$this->idEmpresaa = $idEmpresaa;
return $this;
}
/**
* Get idEmpresaa
*
* #return integer
*/
public function getIdEmpresaa()
{
return $this->idEmpresaa;
}
}
My controller:
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$session = $this->get('session');
$id_empresaa = $session->get('idempresa');
$entities = $em->getRepository('NivalInventarioBundle:InProducto')->findBy(array(
'idEmpresaa' => $id_empresaa
));
return $this->render('NivalInventarioBundle:InProducto:index.html.twig', array(
'entities' => $entities,
));
}
My twig:
{% extends 'NivalInventarioBundle:Default:index.html.twig' %}
{% block content %}
{% block inventario_menu %}
{{ parent() }}
{% endblock %}
<h3>Productos</h3>
<div class="row" style = margin-bottom:55px;">
<div class="col-md-12">
<table id="ftable" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Código</th>
<th>Nombre</th>
<th>Unidad</th>
<th>Costo</th>
<th>Sub-Linea</th>
<th>Linea</th>
<th>Invent.</th>
<th>Factura</th>
<th>Activo</th>
<th>Opción</th>
</tr>
</thead>
<tbody>
{% for entity in entities %}
<tr>
<td>{{ entity.idProducto }}</td>
<td>{{ entity.nombre }}</td>
<td>{{ entity.unidadMedida.nombre }}</td>
<td class="text-right">{{ entity.costoPromedio|number_format(4) }}</td>
<td>{{ entity.subLinea.nombre }}</td>
<td>{{ entity.subLinea.linea.nombre }}</td>
<td>
{% if entity.inventariable == 0 %}
No
{% elseif entity.inventariable == 1 %}
Sí
{% endif %}
</td>
<td>
{% if entity.facturable == 0 %}
No
{% elseif entity.facturable == 1 %}
Sí
{% endif %}
</td>
<td>
{% if entity.activo == 0 %}
No
{% elseif entity.activo == 1 %}
Sí
{% endif %}
</td>
<td class = "actions">
<a href="{{ path('inproducto_show', { 'id': entity.idProducto }) }}"
class = "btn btn-sm btn-info glyphicon glyphicon-search" data-toggle="tooltip" title="Ver"></a>
{% if app.user.nivel > 60 %}
<a href="{{ path('inproducto_edit', { 'id': entity.idProducto }) }}"
class = "btn btn-sm btn-primary glyphicon glyphicon-edit" data-toggle="tooltip" title="Editar"></a>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% if app.user.nivel > 30 %}
<div class="col-md-12">
<a href="{{ path('inproducto_new') }}"
class = "btn btn-success glyphicon glyphicon-plus" data-toggle="tooltip" title="Nuevo"></a>
</div>
{% endif %}
</div>
{% endblock %}
I have been searching on internet, but cant find a solution.
I installed APC in my VPS, and setup the config_prod.yml
doctrine:
orm:
auto_mapping: true
metadata_cache_driver: apc
result_cache_driver: apc
query_cache_driver: apc
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
nested:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
console:
type: console
Please give me a clue!
Set eager fetch mode for associations subLinea and unidadMedida.
With this fetch mode all data from DB will be retrieved in one request.
/**
* #ORM\ManyToOne(targetEntity="InSubLinea", inversedBy="InProducto", fetch="EAGER")
* #ORM\JoinColumn(name="id_sub_linea", referencedColumnName="id")
*/
protected $subLinea;
/**
* #ORM\ManyToOne(targetEntity="InUnidadMedida", inversedBy="InProducto", fetch="EAGER")
* #ORM\JoinColumn(name="id_unidad_medida", referencedColumnName="id")
*/
protected $unidadMedida;
Install twig C extension
http://twig.sensiolabs.org/doc/installation.html#installing-the-c-extension
I used KNPPaginatorBundle to paginate results and It works outstanding, I recomended it: https://github.com/KnpLabs/KnpPaginatorBundle. Checked in this post: How to display large table in twig with symfony?
I just edit the topic details.
I am currently in the process of developing a Forum, which consists of 4 entity:
- Category which includes several forums
- Forum which brings together several topics
- Topic comprising several Posts
- Post which contains answers to topics
Everything works fine for now but one point at a query that I can not achieve.
I would like on the home page of the forum all the categories with sub forums to allow rapid navigation.
The problem I have is that I can not retrieve the post dernirer performed for each forum, and I would like to know how I do for solve this problem ?
So I would like to display all categories associated with all these forums and post the last post in the entity so LastPost topic of each forum.
Here's an overview of what I would do : http://hpics.li/029d17b
My repository :
public function findAllCategory()
{
$qb = $this->createQueryBuilder('c')
->leftJoin('c.forum', 'f')
->addSelect('f')
->leftJoin('f.topic', 't')
->addSelect('t')
->orderBy('c.id', 'DESC');
return $qb->getQuery()
->getResult();
}
My controler :
$categorys = $em->getRepository('AppBundle:Category')->findAllCategory();
Here is my twig file :
{% for category in categorys %}
<div>
<div class="row">
<div class="col-md-12"><h2>{{ category.title }}</h2></div>
</div>
<div class="row">
{% for forum in category.forum %}
<div class="col-md-4">
<h3>{{ forum.title }}</h3>
{{ forum.description }}
Last Post :<br/>
{% if forum.lastPost is not empty %}
{{ forum.topic.title }}
{% endif %}
</div>
{% endfor %}
</div>
</div>
{% endfor %}
My entities :
class Category
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\OneToMany(targetEntity="AppBundle\Entity\Forum", mappedBy="category")
* #ORM\JoinColumn(nullable=true)
*/
private $forum;
/**
* #var string
*
* #ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* #Gedmo\Slug(fields={"title", "id"})
* #ORM\Column(length=128, unique=true)
*/
private $slug;
}
class Forum
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\Category", inversedBy="forum")
* #ORM\JoinColumn(nullable=false)
*/
private $category;
/**
* #ORM\OneToMany(targetEntity="AppBundle\Entity\Topic", mappedBy="forum")
* #ORM\JoinColumn(nullable=true)
*/
private $topic;
/**
* #var string
*
* #ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* #Gedmo\Slug(fields={"title", "id"})
* #ORM\Column(length=128, unique=true)
*/
private $slug;
/**
* #var string
*
* #ORM\Column(name="description", type="string", length=255)
*/
private $description;
/**
* #ORM\OneToOne(targetEntity="AppBundle\Entity\Post")
* #ORM\JoinColumn(nullable=true)
*/
private $lastPost;
}
class Topic
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="UserBundle\Entity\User", inversedBy="topic")
* #ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\Forum", inversedBy="topic")
* #ORM\JoinColumn(nullable=false)
*/
private $forum;
/**
* #ORM\OneToMany(targetEntity="AppBundle\Entity\Post", mappedBy="topic")
* #ORM\JoinColumn(nullable=true)
*/
private $post;
/**
* #var string
*
* #ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* #Gedmo\Slug(fields={"title", "id"})
* #ORM\Column(length=128, unique=true)
*/
private $slug;
/**
* #var \DateTime
*
* #ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;
/**
* #ORM\OneToOne(targetEntity="AppBundle\Entity\Post")
* #ORM\JoinColumn(nullable=true)
*/
private $lastPost;
}
class Post
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="UserBundle\Entity\User", inversedBy="post")
* #ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\Topic", inversedBy="post")
* #ORM\JoinColumn(nullable=false)
*/
private $topic;
/**
* #var string
*
* #ORM\Column(name="message", type="text")
*/
private $message;
/**
* #var \DateTime
*
* #ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;
}
Thanks !
I have a Category entity designed to represent a Forum category. I used StofDoctrineExtensionsBundle in order to use its Tree annotation, in order to have a hierarchy in categories. Now, I would like to represent that hierarchy in a string, some like Category/Subcategory/Subsubcategory/Foo. How can I get all the hierarchy in an unique request with Doctrine ?
// Category.php
use Doctrine\Common\Collections\ArrayCollection;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
/**
* #Gedmo\Tree(type="nested")
* #ORM\Table()
* #ORM\Entity(repositoryClass="PC\ForumBundle\Entity\Repository\CategoryRepository")
*/
class Category
{
/**
* #ORM\Column(type="integer")
* #ORM\Id
* #ORM\GeneratedValue
*/
private $id;
/**
* #ORM\Column(length=64)
*/
private $title;
/**
* #ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* #Gedmo\Slug(fields={"title"})
* #ORM\Column(length=64, unique=true)
*/
private $slug;
/**
* #Gedmo\TreeLeft
* #ORM\Column(type="integer")
*/
private $lft;
/**
* #Gedmo\TreeRight
* #ORM\Column(type="integer")
*/
private $rgt;
/**
* #Gedmo\TreeParent
* #ORM\ManyToOne(targetEntity="Category", inversedBy="children")
* #ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $parent;
/**
* #Gedmo\TreeRoot
* #ORM\Column(type="integer", nullable=true)
*/
private $root;
/**
* #Gedmo\TreeLevel
* #ORM\Column(name="lvl", type="integer")
*/
private $level;
/**
* #ORM\OneToMany(targetEntity="Category", mappedBy="parent")
*/
private $children;
// ...
In complement of palra answer
The repository code :
namespace Foo\MyBundle\Entity;
use Doctrine\ORM\EntityRepository;
use Gedmo\Tree\Entity\Repository\NestedTreeRepository;
class CategoryRepository extends NestedTreeRepository
{
}
A Twig code example (bootstrap) :
<ol class="breadcrumb">
<li><i class="fa fa-home"></i></li>
{% for p in path %}
<li><a {% if loop.last %}class="active"{% endif %}
href="{{ path(...) }}">{{ p.name }}</i></a></li>
{% endfor %}
</ol>
I finally found how to do it :
Make your repository class extend Gedmo\Tree\Entity\Repository\NestedTreeRepository
Call the method getPath($node) on it.
Example :
// Assuming $category is provided by a ParamConverter
public function indexAction(Category $category = null)
{
return array(
'category' => $category,
'path' => $this->repo->getPath($category)
);
}
On my index page are displayed different users. What i want to achieve is when someone click on the username to be redirected on other page where are displayed informations for the user.
Here is part of the twig code which will redirect the user to the hello route.
{% for user in users %}
<strong><em> {{ user.username}}
And this is hello route :
hello:
pattern: /hello
defaults: {_controller:AcmeWebBundle:Default:hello }
I have no idea how to implement this in the contoroler. Can i use variable in which are stored informations for the users from other function or i need to make db query? And how that query to be for particular user who is displayed? In addition is part from the entity. Thanks.
<?php
namespace Acme\Bundle\WebBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* baza
*
* #ORM\Table()
* #ORM\Entity
*/
class baza
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="username", type="string", length=30)
*/
private $username;
/**
* #var string
*
* #ORM\Column(name="password", type="string", length=30)
*/
private $password;
/**
* #var string
*
* #ORM\Column(name="od", type="string", length=30)
*/
private $od;
/**
* #var string
*
* #ORM\Column(name="do", type="string", length=30)
*/
private $do;
/**
* #var float
*
* #ORM\Column(name="cena", type="float")
*/
private $cena;
/**
* #var string
*
* #ORM\Column(name="comment", type="text")
*/
private $comment;
/**
* #var integer
*
* #ORM\Column(name="rating", type="integer")
*/
private $rating;
/**
* #var \DateTime
*
* #ORM\Column(name="date", type="date")
*/
private $date;
/**
* #var string
*
* #ORM\Column(name="car", type="string", length=20)
*/
private $car;
Try this in your template:
{% for user in users %}
<strong><em><a href="{{ path('hello', {"id": user.id}</a>
and this in your routing:
hello:
pattern: /hello/{id}
and your controller will have something like:
public function helloAction(Request $request, $id)
then in your controller retrieve the user by id. This and the rest of it is can be inferred in the book.
Hope this helps