Я работаю с Symfony 3.4 и пакетом l3-db-userbundle, у меня возникла проблема при попытке добавить атрибуты к сущности пакета ...
Это моя сущность в AppBundle \ Entity
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use L3\Bundle\DbUserBundle\Entity\User;
/**
* XUser
*
* @ORM\Table(name="x_user")
* @ORM\Entity
*/
class XUser extends User
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="nombre", type="string", length=100, nullable=false)
*/
private $nombre;
/**
* @var string
*
* @ORM\Column(name="apellido", type="string", length=100, nullable=false)
*/
private $apellido;
/**
* @var string
*
* @ORM\Column(name="dni", type="string", length=20, nullable=false)
*/
private $dni;
/**
* @var string
*
* @ORM\Column(name="uid", type="string", length=15, nullable=false)
*/
private $uid;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="XRole", inversedBy="user")
* @ORM\JoinTable(name="x_user_role",
* joinColumns={
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="role_id", referencedColumnName="id")
* }
* )
*/
private $role;
/**
* Constructor
*/
public function __construct()
{
$this->role = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set id
*
* @param string $id
* @return User
*/
public function setId($id) {
$this->id = $id;
return $this;
}
/**
* @return string
*/
public function getNombre()
{
return $this->nombre;
}
/**
* @param string $nombre
*/
public function setNombre(string $nombre)
{
$this->nombre = $nombre;
}
/**
* @return string
*/
public function getApellido()
{
return $this->apellido;
}
/**
* @param string $apellido
*/
public function setApellido(string $apellido)
{
$this->apellido = $apellido;
}
/**
* @return string
*/
public function getDni()
{
return $this->dni;
}
/**
* @param string $dni
*/
public function setDni(string $dni)
{
$this->dni = $dni;
}
/**
* @return string
*/
public function getUid()
{
return $this->uid;
}
/**
* Set uid
*
* @param string $uid
* @return User
*/
public function setUid($uid) {
$this->uid = $uid;
return $this;
}
/**
* @return \Doctrine\Common\Collections\Collection
*/
public function getRole()
{
return $this->role;
}
/**
* @param \Doctrine\Common\Collections\Collection $role
*/
public function setRole(\Doctrine\Common\Collections\Collection $role)
{
$this->role = $role;
}
}
А это класс вендора
<?php
namespace L3\Bundle\DbUserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Table(name="x_user")
* @ORM\Entity(repositoryClass="L3\Bundle\DbUserBundle\Repository \UserRepository")
*/
class User implements UserInterface, \Serializable {
/**
* @var integer $id
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(name="uid", type="string", length=15)
*/
private $uid;
/**
* @ORM\ManyToMany(targetEntity="Role", cascade={"persist"})
* @ORM\JoinTable(name="x_user_role",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
* )
* @var ArrayCollection $roles
*/
private $roles;
public function __construct() {
}
/**
* Get id
*
* @return integer
*/
public function getId() {
return $this->id;
}
/**
* Set id
*
* @param string $id
* @return User
*/
public function setId($id) {
$this->id = $id;
return $this;
}
/**
* Get uid
*
* @return string
*/
public function getUid() {
return $this->uid;
}
/**
* Set uid
*
* @param string $uid
* @return User
*/
public function setUid($uid) {
$this->uid = $uid;
return $this;
}
//Source : http://www.metod.si/symfony2-error-usernamepasswordtokenserialize-must-return-a-string-or-null/
public function serialize() {
return serialize(array(
$this->id,
$this->uid
));
}
public function unserialize($serialize) {
list(
$this->id,
$this->uid
) = unserialize($serialize);
}
public function eraseCredentials() {
//pas d'implémentation nécessaire
}
public function getPassword() {
//pas d'implémentation nécessaire
}
public function getRoles() {
$roles = array();
foreach ($this->roles as $role) {
if (!in_array($role->getRole(), $roles)) {
$roles[] = $role->getRole();
}
}
$roles[] = "ROLE_USER";
return $roles;
}
public function getSalt() {
//pas d'implémentation nécessaire
}
public function getUsername() {
return $this->getUid();
}
public function __toString() {
return $this->getUid();
}
}
Когда я пытаюсь получить данные из базы данных, появляется ошибка: попытка вызова неопределенного метода с именем "getNombre"класса "L3 \ Bundle \ DbUserBundle \ Entity \ User".
Это метод, в котором у меня проблема:
<?php
namespace AppBundle\Controller;
use AppBundle\Entity\XUser;
use AppBundle\Entity\XUserOffice;
use AppBundle\Form\UserType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* Class UserController
* @Route("/users")
*/
class UserController extends Controller
{
/**
* @Route("/", name="users_list")
* @Template("@App/user/index.html.twig")
*/
public function indexAction(Request $request)
{
$users = $this->getDoctrine()->getRepository('AppBundle:XUser')->findAll();
$list = [];
foreach ($users as $user) {
$role = $this->getRole($user->getId());
$dat['id'] = $user->getId();
$dat['name'] = $user->getNombre() . ' ' . $user->getApellido();
$dat['dni'] = $user->getDni();
$dat['role'] = $role['role'];
$list[] = $dat;
}
return [
'list' => $list
];
}