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)
);
}
Related
I'm using FOSUserBundle with custom fields in my user class.
<?php
namespace AppBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* #ORM\Entity
* #ORM\Table(name="fos_user")
* #ORM\Entity(repositoryClass="AppBundle\Entity\UserRepository")
*/
class User extends BaseUser {
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #ORM\Column(type="string", length=255)
*
* #Assert\NotBlank(message="Please enter your name.", groups={"Registration", "Profile"})
* #Assert\Length(min="3", max="255", groups={"Registration", "Profile"})
*/
protected $name;
/**
* #ORM\OneToMany(targetEntity="AppBundle\Entity\Message", mappedBy="fromUser")
*/
protected $sentMessages;
/**
* #ORM\OneToMany(targetEntity="AppBundle\Entity\Message", mappedBy="toUser")
*/
protected $receivedMessages;
/**
* #ORM\Column(type="date")
*/
protected $dateRegistered;
/**
* #ORM\Column(type="string", length=250, nullable=true)
*
*/
protected $banReason;
public function __construct() {
parent::__construct();
$this->dateRegistered = new \DateTime();
}
/* getters and setters */
}
I want to show a personal message to the locked users, filling $banReason field.
I found that error.user variable contains part of the user entity, but my field is set to null instead of it's real value.
Sorry, but i'm kinda noob in hooks and services. :-(
Have a nice day!
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 !
Im using Gedmo Translatable in my project.
I have Product entity and Inclusion entity.
Relation between them is ManyToMany.
Product Entity
namespace Traffic\ShopBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Traffic\ShopBundle\Model\Product as ProductModel;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* #ORM\Entity(repositoryClass="Traffic\ShopBundle\Repository\ProductRepository")
* #Gedmo\TranslationEntity(class="Traffic\ShopBundle\Entity\ProductTranslation")
*
*/
class Product extends ProductModel {
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #ORM\Column(type="string", length=255)
* #Gedmo\Translatable
*
* #var type string
*/
protected $name;
/**
* #ORM\ManyToMany(targetEntity="Inclusion")
* #ORM\JoinTable(name="product_inclusion",
* joinColumns={#ORM\JoinColumn(name="product_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="inclusion_id", referencedColumnName="id")}
* )
*
* #var type Collection
*/
protected $inclusions;
/**
* #ORM\OneToMany(
* targetEntity="ProductTranslation",
* mappedBy="object",
* cascade={"persist", "remove"}
* )
*/
protected $translations;
.....
}
Inclusion Entity
namespace Traffic\ShopBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Traffic\ShopBundle\Model\Inclusion as InclusionModel;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* #ORM\Entity(repositoryClass="Traffic\AdminBundle\Repository\TranslatableRepository")
* #ORM\InheritanceType("SINGLE_TABLE")
* #ORM\DiscriminatorColumn(name="discr", type="string")
* #ORM\DiscriminatorMap({"sauce" = "Sauce", "topping" = "Topping"})
* #Gedmo\SoftDeleteable(fieldName="deletedAt")
* #Gedmo\TranslationEntity(class="Traffic\ShopBundle\Entity\InclusionTranslation")
*
* #ORM\Table(name="inclusion")
*/
class Inclusion extends InclusionModel {
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #ORM\Column(type="string", length=255)
* #Gedmo\Translatable
*
* #var type string
*/
protected $name;
/**
* #ORM\OneToMany(
* targetEntity="InclusionTranslation",
* mappedBy="object",
* cascade={"persist", "remove"}
* )
*/
protected $translations;
.......
}
In my Repository class I have a method to fetch translated object, but it just translates my Product not Inclusions
namespace Traffic\ShopBundle\Repository;
use Traffic\AdminBundle\Repository\TranslatableRepository;
use Traffic\ShopBundle\Entity\Kiosk;
/**
* Description of FinancialTransactionRepository
*
* #author bart
*/
class ProductRepository extends TranslatableRepository {
public function findAllProductsForKiosk(Kiosk $kiosk, $locale = "es"){
$qb = $this->createQueryBuilder("p")
->leftJoin('p.kiosks', 'k')
->leftJoin('p.flavours', 'f')
->leftJoin('p.inclusions', "i")
->leftJoin('p.type', "t")
->where('k.kiosk = :kiosk')
;
$qb->setParameter("kiosk", $kiosk);
$results = $this->getTranslatedQuery($qb, $locale);
return $results->execute();
}
}
and getTranslatedQuery
/**
* Returns translated Doctrine query instance
*
* #param QueryBuilder $qb A Doctrine query builder instance
* #param string $locale A locale name
*
* #return Query
*/
protected function getTranslatedQuery(QueryBuilder $qb, $locale = null)
{
$locale = null === $locale ? $this->defaultLocale : $locale;
$query = $qb->getQuery();
$query->setHint(
Query::HINT_CUSTOM_OUTPUT_WALKER,
'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker'
);
$query->setHint(TranslatableListener::HINT_TRANSLATABLE_LOCALE, $locale);
return $query;
}
Is there a way to fetch all translated objects with one query?
Maybe you should change hydration mode?
$query->setHydrationMode(TranslationWalker::HYDRATE_OBJECT_TRANSLATION);
$config = $this->container->get('doctrine')->getManager()->getConfiguration();
if ($config->getCustomHydrationMode(TranslationWalker::HYDRATE_OBJECT_TRANSLATION) === null) {
$config->addCustomHydrationMode(
TranslationWalker::HYDRATE_OBJECT_TRANSLATION,
'Gedmo\\Translatable\\Hydrator\\ORM\\ObjectHydrator'
);
}
I hope someone could help me, maybe this is a bug or there is solution for it..
I have a job entity which has ManyToOne relation to client entity.
class Job {
/**
* #ORM\ManyToOne(targetEntity="Client")
*/
protected $client;}
When I get client from controller
$client = $job->getClient();
// I could get client id here in controller, but could not render in twig template
$clientId = $client->getId();
return $this->render('client' => $client);
and render it in template
{{ client.id|default('0') }}
It always output 0,
but all other properties of client entity can output properly.
{{ client.name }} ----> this can print out properly, except {{ client.id }}
and I use Netbeans debug windows, I saw this client entity is a proxy entity, and it's __isInitialized__ value is 0, if I set:
$real_client = $em->getRepository('AceCoreBundle:Client')->find(4);
this is real entity and can output client id in twig.
Even I have a proxy entity with __isInitialized__ value is 1, it also can output the id value of the entity in twig.
Not sure what 's wrong with it..
Because of this problem, every time I have to render 'client_id' => $clientId separately to twig
return $this->render(array('client_id' => $clientId, 'client' => $client));
{{ client_id|default('0') }} // in twig
is there anyway I can convert proxy entity to real entity?
Part of My Client entity code as below:
Client.php
// doctrine
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
/**
* #ORM\Entity()
* #ORM\Table(name="client")
* #Gedmo\SoftDeleteable(fieldName="deletedAt")
*/
class Client {
const STATUS_NEW = 0; // new client
const STATUS_APPROVED = 1; // client approved by accounting team
/**
* #ORM\Id
* #ORM\GeneratedValue
* #ORM\Column(type="integer")
*/
public $id;
/*
* #ORM\OneToOne(targetEntity="\Acme\UserBundle\Entity\User")
*
//protected $user; */
/**
* #ORM\OneToOne(targetEntity="Contact")
#ORM\JoinColumn(name="primary_contact_id", referencedColumnName="id")
*/
protected $primaryContact;
/**
* #ORM\OneToMany(targetEntity="Contact", mappedBy="client")
*/
protected $contacts;
/**
* #ORM\OneToMany(targetEntity="\Acme\QuoteBundle\Entity\Costing", mappedBy="client")
*/
protected $costings;
/**
* #ORM\OneToMany(targetEntity="\Acme\JobBundle\Entity\Job", mappedBy="client")
*/
protected $jobs;
/**
* #ORM\Column(length=20, nullable=true)
*/
protected $code;
/**
* #ORM\Column(name="display_name",length=150,unique=true)
*/
protected $displayName;
/**
* #ORM\Column(name="created_at", type="datetime")
*/
protected $createdAt;
/**
* #ORM\Column(name="delivery_addr",type="text",nullable=true)
*/
protected $deliveryAddr;
/**
* #ORM\Column(length=200, nullable=true)
* #Assert\NotBlank()
*/
protected $street;
/**
* #ORM\Column(length=50, nullable=true)
*/
protected $suburb;
/**
* #ORM\Column(length=50, nullable=true)
*/
protected $city;
/**
* #ORM\Column(length=4, nullable=true)
* #Assert\Length(
* min = "0",
* max = "4",
* minMessage = "",
* maxMessage = "The postcode cannot be longer than than {{ limit }} characters length"
* )
*/
protected $postcode;
/**
* #ORM\Column(name="courier_post_aid", type="integer")
*/
protected $courierPostAid;
/**
* #ORM\Column(name="invoice_addr",type="text", nullable=true)
*/
protected $invoiceAddr;
/**
* #ORM\ManyToOne(targetEntity="Acme\CoreBundle\Entity\Staff")
* #ORM\JoinColumn(name="account_manager", referencedColumnName="id")
*/
protected $accountManager;
/**
* #ORM\Column(type="smallint")
*/
protected $status;
/**
* #ORM\Column(type="boolean",name="is_reseller", nullable=true)
*/
protected $isReseller;
/**
* #ORM\Column(name="deleted_at", type="datetime", nullable=true)
*/
protected $deletedAt;
/**
* CONSTRUCTER OF CLASS
*/
public function __construct() {
$this->contacts = new ArrayCollection();
$this->status = $this::STATUS_NEW;
$this->createdAt = new \DateTime();
$this->isReseller = false;
$this->courierPostAid = 0;
}
Part of Job Entity code:
Job.php
// doctrine
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* #ORM\Entity(repositoryClass="Acme\JobBundle\Repository\JobRepository")
* #ORM\Table(name="job")
* #Gedmo\Loggable
* #Gedmo\SoftDeleteable(fieldName="deletedAt")
*/
class Job {
/**
* #ORM\Id
* #ORM\GeneratedValue
* #ORM\Column(type="integer")
*/
public $id;
/**
* #ORM\Column(type="integer", name="prev_job_id")
*/
private $prevJobId;
/**
* #ORM\ManyToOne(targetEntity="Acme\CoreBundle\Entity\Category")
*/
protected $category;
/**
* #ORM\Column(name="job_num",length=20)
*/
protected $jobNum;
/**
* #ORM\Column(name="prev_job_num",length=20, nullable=true)
*/
protected $prevJobNum;
/**
* #ORM\Column(name="costing_num",length=20)
*/
protected $costingNum;
/**
* #ORM\ManyToOne(targetEntity="\Acme\CoreBundle\Entity\Client", inversedBy="jobs")
*/
protected $client;
/**
* #ORM\Column(name="contact_id",type="smallint", nullable=true)
*/
protected $contactId;
/**
* #ORM\Column(length=50, name="contact_firstname")
*/
protected $contactFirstName;
/**
* #ORM\Column(length=50, name="contact_lastname", nullable=true)
*/
protected $contactLastName;
/**
* #ORM\Column(name="name",length=255)
*/
protected $name;
/**
* #ORM\Column(name="special_instruction", type="text", nullable=true)
* #Gedmo\Versioned
*/
protected $specialInstruction;
/**
* #ORM\Column(name="date_in", type="datetime")
*/
protected $dateIn;
/**
* #ORM\Column(name="date_out", type="datetime")
*/
protected $dateOut;
/**
* #ORM\ManyToOne(targetEntity="Acme\CoreBundle\Entity\Staff")
* #ORM\JoinColumn(name="account_manager", referencedColumnName="id")
*/
protected $accountManager;
/**
* #ORM\Column(name="job_data", type="array")
* #Gedmo\Versioned
*/
protected $jobData;
/**
* #ORM\Column(name="created_at", type="datetime")
*/
protected $createdAt;
/**
* #ORM\ManyToOne(targetEntity="Acme\CoreBundle\Entity\Staff")
* #ORM\JoinColumn(name="created_by", referencedColumnName="id")
*/
protected $createdBy;
/**
* #ORM\Column(name="modified_at", type="datetime", nullable=true)
*/
protected $modifiedAt;
/**
* #ORM\ManyToOne(targetEntity="Acme\CoreBundle\Entity\Staff")
* #ORM\JoinColumn(name="modified_by", referencedColumnName="id")
*/
protected $modifiedBy;
/**
* #ORM\Column(name="deleted_at", type="datetime", nullable=true)
*/
protected $deletedAt;
// CONSTRUCTION
public function __construct() {
$this->createdAt = new \DateTime();
$this->dateIn = new \DateTime();
$this->prevJobId = 0;
}
JobController.php
public function editAction($id) {
$em = $this->getDoctrine()->getManager();
$request = $this->getRequest();
$job = $em->getRepository('AcmeJobBundle:Job')->find($id);
if (!$job) {
throw $this->createNotFoundException('Unable to find job entity.');
}
$client = $job->getClient();
return array(
'client' => $client,
);
}
edit.html.twig
<input type=hidden id="client-id" value="{{ client.id }}" name="client_id">
I tried to use NetBeans to debug it, I found that when I change app/cache/dev/classes.php , about line 4867, in function getAttribute, I add some code below
// if I add this change to , it can print out id properly...
if ($item == 'id') {
return $object->getId();
}
before:
return $object->$item;
Then I can print out the id attribute in twig..
My best guess would be that this is due to doctrine lazy loading the client entity. You should try switching your controller's doctrine call to a repository method with a join query on clients (don't forget to use paginator if needed). Or switch the default fetch mode on your entity (I don't remember exacts steps for this).
Still a weird error, please post your client entity code for better assist.
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