Answer the question
In order to leave comments, you need to log in
How to correctly implement symfony 2 authorization?
I started to study this framework and I can’t understand how to solve the problem of authorizing users stored in the database correctly.
After reading the documentation, unfortunately in English, with which I am not very friendly, it became clear that this should be done using FOSUserBundle.
Somehow, having installed according to the instructions, I got the opportunity to create users, groups.
But as always, there were questions that I could not find answers to in the documentation.
1) There is some entity users which inherits FOS\UserBundle\Model\User.
contains additional entries.
<?php
namespace ACVote\UsersBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="Users")
*/
class Users extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="name", type="string", length=255, nullable=true)
*/
private $name;
/**
* @ORM\Column(name="surname", type="string", length=255, nullable=true)
*/
private $surname;
/**
* @ORM\ManyToMany(targetEntity="ACVote\UsersBundle\Entity\Groups")
* @ORM\JoinTable(name="fos_user_user_group",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}
* )
*/
protected $groups;
public function __construct()
{
parent::__construct();
// your own logic
}
Answer the question
In order to leave comments, you need to log in
what should be done with FOSUserBundle.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question