I'm working on small Symfony project. Besides everything it contains User authorization and profile. I added FOSUserBundle for this needs, it works great from the box btw.
Here is my show_content.html.twig
, actually it's almost the same as it goes from the box:
{% trans_default_domain 'FOSUserBundle' %}
<div class="fos_user_user_show">
<p>{{ 'profile.show.email'|trans }}: {{ user.email }}</p>
<p>{{ 'profile.show.points'|trans }}: {{ user.points }}</p>
<p><a href="{{ path('fos_user_security_logout') }}">Logout</a></p>
</div>
Each user can earn points. I created simple entity for it:
<?php
namespace Acme\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="fos_user_points")
*/
class Points
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string")
*/
protected $datetime;
/**
* @ORM\Column(type="integer")
*/
protected $points;
/**
* @ORM\Column(type="string")
*/
protected $email;
//Getters and setters go here
}
I also added a simple form where a user can press a button and randomly generated points goes to his account. It worked well, as it was just was one more variable in a User entity. But now I need to implement points getting history in a user profile. This why Points entity was created. I see points are running to fos_user_points table, but how do I put this content to the User profile? I'm not sure if it's safe to directly grab 'em from a database.