Reputation: 123
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><a href="{{ path('hello') }}"> {{ user.username}}</a>
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;
Upvotes: 1
Views: 232
Reputation: 4714
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
Upvotes: 2