Symfony 2: with passwords encryption - php

$factory = $this->get('security.encoder_factory');
var_dump($factory);
$encoder = $factory->getEncoder($user);
//$encoder = new MessageDigestPasswordEncoder('sha512', true, 10);
$password = $encoder->encodePassword($user->getUserPass(), $user->getUserSalt());
$user->setUserPass($password);
The error
Catchable Fatal Error: Argument 1 passed to Symfony\Component\Security\Core\Encoder\EncoderFactory::getEncoder() must implement interface Symfony\Component\Security\Core\User\UserInterface, instance of Acme\AdminBundle\Entity\SyjUsers given, called in D:\Zend\joke\src\Acme\AdminBundle\Controller\AdminController.php on line 28 and defined in D:\Zend\joke\vendor\symfony\src\Symfony\Component\Security\Core\Encoder\EncoderFactory.php line 33
500 Internal Server Error - ErrorException
The user entity
<?php
namespace Acme\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* Acme\UserBundle\Entity\SyjUsers
*
* #ORM\Table(name="syj_users")
*
* #ORM\Entity
*/
class SyjUsers implements UserInterface
{
/**
* #var integer $id
*
* #ORM\Column(name="id", type="integer", nullable=false)
*
* #ORM\Id
*
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string $userLogin
*
* #ORM\Column(name="user_login", type="string", length=60, nullable=false)
*/
private $userLogin;
/**
* #var string $userSalt
*
* #ORM\Column(name="user_salt", type="string", length=64, nullable=false)
*/
private $userSalt;
/**
* #var string $userPass
*
* #ORM\Column(name="user_pass", type="string", length=64, nullable=false)
*/
private $userPass;
/**
* #var string $userNicename
*
* #ORM\Column(name="user_nicename", type="string", length=60, nullable=true)
*/
private $userNicename;
/**
* #var string $userEmail
*
* #ORM\Column(name="user_email", type="string", length=100, nullable=true)
*/
private $userEmail;
/**
* #var string $userUrl
*
* #ORM\Column(name="user_url", type="string", length=60, nullable=true)
*/
private $userUrl;
/**
* #var boolean $userStatus
*
* #ORM\Column(name="user_status", type="boolean", nullable=false)
*/
private $userStatus;
/**
* #var string $userDisplayName
*
* #ORM\Column(name="user_display_name", type="string", length=60, nullable=true)
*/
private $userDisplayName;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set userLogin
*
* #param string $userLogin
*/
public function setUserLogin($userLogin)
{
$this->userLogin = $userLogin;
}
/**
* Get userLogin
*
* #return string
*/
public function getUserLogin()
{
return $this->userLogin;
}
/**
* Set userSalt
*
* #param string $userSalt
*/
public function setUserSalt($userSalt)
{
$this->userSalt = $userSalt;
}
/**
* Get userSalt
*
* #return string
*/
public function getUserSalt()
{
return $this->userSalt;
}
/**
* Set userPass
*
* #param string $userPass
*/
public function setUserPass($userPass)
{
$this->userPass = $userPass;
}
/**
* Get userPass
*
* #return string
*/
public function getUserPass()
{
return $this->userPass;
}
/**
* Set userNicename
*
* #param string $userNicename
*/
public function setUserNicename($userNicename)
{
$this->userNicename = $userNicename;
}
/**
* Get userNicename
*
* #return string
*/
public function getUserNicename()
{
return $this->userNicename;
}
/**
* Set userEmail
*
* #param string $userEmail
*/
public function setUserEmail($userEmail)
{
$this->userEmail = $userEmail;
}
/**
* Get userEmail
*
* #return string
*/
public function getUserEmail()
{
return $this->userEmail;
}
/**
* Set userUrl
*
* #param string $userUrl
*/
public function setUserUrl($userUrl)
{
$this->userUrl = $userUrl;
}
/**
* Get userUrl
*
* #return string
*/
public function getUserUrl()
{
return $this->userUrl;
}
/**
* Set userStatus
*
* #param boolean $userStatus
*/
public function setUserStatus($userStatus)
{
$this->userStatus = $userStatus;
}
/**
* Get userStatus
*
* #return boolean
*/
public function getUserStatus()
{
return $this->userStatus;
}
/**
* Set userDisplayName
*
* #param string $userDisplayName
*/
public function setUserDisplayName($userDisplayName)
{
$this->userDisplayName = $userDisplayName;
}
/**
* Get userDisplayName
*
* #return string
*/
public function getUserDisplayName()
{
return $this->userDisplayName;
}
/**
* #inheritDoc
*/
public function getUsername()
{
return $this->userLogin;
}
/**
* #inheritDoc
*/
public function getSalt()
{
return $this->userSalt;
}
/**
* #inheritDoc
*/
public function getPassword()
{
return $this->userPass;
}
/**
* #inheritDoc
*/
public function getRoles()
{
return array('ROLE_USER');
}
/**
* #inheritDoc
*/
public function eraseCredentials()
{
}
/**
* #inheritDoc
*/
public function equals(UserInterface $user)
{
return $this->userLogin === $user->getUsername();
}
}

Have you tryed to
implements CustomUserInterface
instead of the
implements UserInterface

Related

Fill Selectbox with database data - Forms + Doctrine + Symfony 3

I am trying to populate my form with an List of Results from query with Doctrine
But i`m getting this error:
Catchable Fatal Error: Object of class AppBundle\Entity\Parceiros could not be converted to string
Here is my Form CoberturasType
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
class CoberturasType extends AbstractType
{
/**
* #param FormBuilderInterface $builder
* #param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('descricao')
->add('parceiro', EntityType::class, [
'class'=>'AppBundle:Parceiros',
])
;
}
/**
* #param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\Coberturas'
));
}
}
Here is my CoberturasEntity
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Coberturas
*
* #ORM\Table(name="coberturas")
* #ORM\Entity(repositoryClass="AppBundle\Repository\CoberturasRepository")
* #ORM\Entity()
* #ORM\HasLifecycleCallbacks()
*/
class Coberturas
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="Parceiros")
* #ORM\JoinColumn(name="parceiro", referencedColumnName="id", nullable=false)
*/
protected $parceiro;
/**
* #var string
*
* #ORM\Column(name="descricao", type="string", length=120)
*/
private $descricao;
/**
* #var bool
*
* #ORM\Column(name="_ativo", type="boolean")
*/
private $ativo;
/**
* #var \DateTime
*
* #ORM\Column(name="created", type="datetime")
*/
private $created;
/**
* #var string
*
* #ORM\Column(name="updated", type="datetime")
*/
private $updated;
/**
* #var bool
*
* #ORM\Column(name="_deletado", type="boolean")
*/
private $deletado;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set descricao
*
* #param string $descricao
*
* #return Coberturas
*/
public function setDescricao($descricao)
{
$this->descricao = $descricao;
return $this;
}
/**
* Get descricao
*
* #return string
*/
public function getDescricao()
{
return $this->descricao;
}
/**
* Set ativo
*
* #param boolean $ativo
*
* #return Coberturas
*/
public function setAtivo($ativo)
{
$this->ativo = $ativo;
return $this;
}
/**
* Get ativo
*
* #return bool
*/
public function getAtivo()
{
return $this->ativo;
}
/**
* Set created
*
* #param \DateTime $created
*
* #return Coberturas
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* Get created
*
* #return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set updated
*
* #param string $updated
*
* #return Coberturas
*/
public function setUpdated($updated)
{
$this->updated = $updated;
return $this;
}
/**
* Get updated
*
* #return string
*/
public function getUpdated()
{
return $this->updated;
}
/**
* Set deletado
*
* #param boolean $deletado
*
* #return Coberturas
*/
public function setDeletado($deletado)
{
$this->deletado = $deletado;
return $this;
}
/**
* Get deletado
*
* #return bool
*/
public function getDeletado()
{
return $this->deletado;
}
/**
* #ORM\PrePersist
*/
public function setCreatedValue()
{
$this->created = new \DateTime();
}
/**
* #ORM\postUpdate
*/
public function setUpdatedValue()
{
$this->updated = new \DateTime();
}
/**
* Set parceiro
*
* #param \AppBundle\Entity\Parceiros $parceiro
*
* #return Coberturas
*/
public function setParceiro(\AppBundle\Entity\Parceiros $parceiro = null)
{
$this->parceiro = $parceiro;
return $this;
}
/**
* Get parceiro
*
* #return \AppBundle\Entity\Parceiros
*/
public function getParceiro()
{
return $this->parceiro;
}
}
Here is my ParceirosEntity
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Parceiros
*
* #ORM\Table(name="parceiros")
* #ORM\Entity(repositoryClass="AppBundle\Repository\ParceirosRepository")
* #ORM\Entity()
* #ORM\HasLifecycleCallbacks()
*/
class Parceiros
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
* #ORM\OneToMany(targetEntity="Coberturas", mappedBy="parceiro")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="razaoSocial", type="string", length=255)
*/
private $razaoSocial;
/**
* #var string
*
* #ORM\Column(name="nomeFantasia", type="string", length=255, nullable=true)
*/
private $nomeFantasia;
/**
* #var string
*
* #ORM\Column(name="cnpj", type="string", length=17, nullable=true)
*/
private $cnpj;
/**
* #var string
*
* #ORM\Column(name="inscEstadual", type="string", length=60, nullable=true)
*/
private $inscEstadual;
/**
* #var string
*
* #ORM\Column(name="cep", type="string", length=9, nullable=true)
*/
private $cep;
/**
* #var string
*
* #ORM\Column(name="endereco", type="string", length=160, nullable=true)
*/
private $endereco;
/**
* #var string
*
* #ORM\Column(name="numero", type="string", length=30, nullable=true)
*/
private $numero;
/**
* #var string
*
* #ORM\Column(name="complemento", type="string", length=30, nullable=true)
*/
private $complemento;
/**
* #var string
*
* #ORM\Column(name="bairro", type="string", length=80, nullable=true)
*/
private $bairro;
/**
* #var string
*
* #ORM\Column(name="cidade", type="string", length=100, nullable=true)
*/
private $cidade;
/**
* #var string
*
* #ORM\Column(name="estado", type="string", length=2, nullable=true)
*/
private $estado;
/**
* #var \DateTime
*
* #ORM\Column(name="created", type="datetime", nullable=true)
*/
private $created;
/**
* #var \DateTime
*
* #ORM\Column(name="updated", type="datetime", nullable=true)
*/
private $updated;
/**
* #var bool
*
* #ORM\Column(name="ativo", type="boolean", nullable=true)
*/
private $ativo = 1;
/**
* #var bool
*
* #ORM\Column(name="deletado", type="boolean", nullable=true)
*/
private $deletado = 0;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set razaoSocial
*
* #param string $razaoSocial
*
* #return Parceiros
*/
public function setRazaoSocial($razaoSocial)
{
$this->razaoSocial = $razaoSocial;
return $this;
}
/**
* Get razaoSocial
*
* #return string
*/
public function getRazaoSocial()
{
return $this->razaoSocial;
}
/**
* Set nomeFantasia
*
* #param string $nomeFantasia
*
* #return Parceiros
*/
public function setNomeFantasia($nomeFantasia)
{
$this->nomeFantasia = $nomeFantasia;
return $this;
}
/**
* Get nomeFantasia
*
* #return string
*/
public function getNomeFantasia()
{
return $this->nomeFantasia;
}
/**
* Set cnpj
*
* #param string $cnpj
*
* #return Parceiros
*/
public function setCnpj($cnpj)
{
$this->cnpj = $cnpj;
return $this;
}
/**
* Get cnpj
*
* #return string
*/
public function getCnpj()
{
return $this->cnpj;
}
/**
* Set inscEstadual
*
* #param string $inscEstadual
*
* #return Parceiros
*/
public function setInscEstadual($inscEstadual)
{
$this->inscEstadual = $inscEstadual;
return $this;
}
/**
* Get inscEstadual
*
* #return string
*/
public function getInscEstadual()
{
return $this->inscEstadual;
}
/**
* Set cep
*
* #param string $cep
*
* #return Parceiros
*/
public function setCep($cep)
{
$this->cep = $cep;
return $this;
}
/**
* Get cep
*
* #return string
*/
public function getCep()
{
return $this->cep;
}
/**
* Set endereco
*
* #param string $endereco
*
* #return Parceiros
*/
public function setEndereco($endereco)
{
$this->endereco = $endereco;
return $this;
}
/**
* Get endereco
*
* #return string
*/
public function getEndereco()
{
return $this->endereco;
}
/**
* Set numero
*
* #param string $numero
*
* #return Parceiros
*/
public function setNumero($numero)
{
$this->numero = $numero;
return $this;
}
/**
* Get numero
*
* #return string
*/
public function getNumero()
{
return $this->numero;
}
/**
* Set complemento
*
* #param string $complemento
*
* #return Parceiros
*/
public function setComplemento($complemento)
{
$this->complemento = $complemento;
return $this;
}
/**
* Get complemento
*
* #return string
*/
public function getComplemento()
{
return $this->complemento;
}
/**
* Set bairro
*
* #param string $bairro
*
* #return Parceiros
*/
public function setBairro($bairro)
{
$this->bairro = $bairro;
return $this;
}
/**
* Get bairro
*
* #return string
*/
public function getBairro()
{
return $this->bairro;
}
/**
* Set cidade
*
* #param string $cidade
*
* #return Parceiros
*/
public function setCidade($cidade)
{
$this->cidade = $cidade;
return $this;
}
/**
* Get cidade
*
* #return string
*/
public function getCidade()
{
return $this->cidade;
}
/**
* Set estado
*
* #param string $estado
*
* #return Parceiros
*/
public function setEstado($estado)
{
$this->estado = $estado;
return $this;
}
/**
* Get estado
*
* #return string
*/
public function getEstado()
{
return $this->estado;
}
/**
* Set created
*
* #param \DateTime $created
*
* #return Parceiros
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* Get created
*
* #return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set updated
*
* #param \DateTime $updated
*
* #return Parceiros
*/
public function setUpdated($updated)
{
$this->updated = $updated;
return $this;
}
/**
* Get updated
*
* #return \DateTime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* Set ativo
*
* #param boolean $ativo
*
* #return Parceiros
*/
public function setAtivo($ativo)
{
$this->ativo = $ativo;
return $this;
}
/**
* Get ativo
*
* #return bool
*/
public function getAtivo()
{
return $this->ativo;
}
/**
* Set deletado
*
* #param boolean $deletado
*
* #return Parceiros
*/
public function setDeletado($deletado)
{
$this->deletado = $deletado;
return $this;
}
/**
* Get deletado
*
* #return bool
*/
public function getDeletado()
{
return $this->deletado;
}
/**
* #ORM\PrePersist
*/
public function setCreatedValue()
{
$this->created = new \DateTime();
}
/**
* #ORM\postUpdate
*/
public function setUpdatedValue()
{
$this->updated = new \DateTime();
}
}
I just wanna show an SelectBox to user select for what "parceiro" he wanna insert a new "cobertura".
Thanks for the help...

replace the authentication layer and user entity in sylius

I have created a symfony2 project and custom Authentication Provider (http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html) is used. my new task is to create an E-commerce application in sylius which should work alongside with my current symfony2 project. i want to make my current user table in symfony2 project as user provider in sylius...is it possible to create such project..... since fosUserBundle and fosOauthServer bundel are installed in sylius how can i override these bundles with my custom authentication mechanism
My symfony2 project configurations are mentioned below
I tried the following in security.yml
security:
encoders:
AppBundle\Entity\Users:
algorithm: bcrypt
providers:
our_db_provider:
entity:
class: AppBundle:Users
api_key_user_provider:
id: api_key_user_provider
firewalls:
dev:
pattern: ^/(_(profiler|wdt|error)|css|images|js)/
security: false
api:
pattern: ^/api
stateless: true
simple_preauth:
authenticator: apikey_authenticator
provider: api_key_user_provider
web:
anonymous: ~
http_basic: ~
provider: our_db_provider
form_login:
login_path: /login
check_path: /login_check
this is my user class
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* Users
*
* #ORM\Table(name="users", uniqueConstraints= {#ORM\UniqueConstraint(name="users_user_name_unique", columns={"user_name"}), #ORM\UniqueConstraint(name="users_xmpp_password_unique", columns= {"xmpp_password"})})
* #ORM\Entity(repositoryClass="AppBundle\Entity\UsersRepository")
*/
class Users implements UserInterface, \Serializable {
/**
* #var integer
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var integer
*
* #ORM\Column(name="parent_id", type="integer", nullable=false)
*/
private $parentId;
/**
* #var string
*
* #ORM\Column(name="first_name", type="string", length=100, nullable=false)
*/
private $firstName;
/**
* #var string
*
* #ORM\Column(name="last_name", type="string", length=100, nullable=false)
*/
private $lastName;
/**
* #var string
*
* #ORM\Column(name="user_name", type="string", length=120, nullable=false)
*/
private $userName;
/**
* #var string
*
* #ORM\Column(name="reg_type", type="string", length=20, nullable=false)
*/
private $regType;
/**
* #var string
*
* #ORM\Column(name="oauth_uid", type="string", length=255, nullable=false)
*/
private $oauthUid;
/**
* #var boolean
*
* #ORM\Column(name="active", type="boolean", nullable=false)
*/
private $active;
/**
* #var string
*
* #ORM\Column(name="email", type="string", length=100, nullable=false)
*/
private $email;
/**
* #var string
*
* #ORM\Column(name="password", type="string", length=150, nullable=false)
*/
private $password;
/**
* #var string
*
* #ORM\Column(name="xmpp_password", type="string", length=20, nullable=false)
*/
private $xmppPassword;
/**
* #var \DateTime
*
* #ORM\Column(name="created_at", type="datetime", nullable=false)
*/
private $createdAt = '0000-00-00 00:00:00';
/**
* #var \DateTime
*
* #ORM\Column(name="updated_at", type="datetime", nullable=false)
*/
private $updatedAt = '0000-00-00 00:00:00';
/**
* #var \DateTime
*
* #ORM\Column(name="deleted_at", type="datetime", nullable=true)
*/
private $deletedAt;
/**
* #var string
*
* #ORM\Column(name="activation_code", type="string", length=50, nullable=true)
*/
private $activationCode;
/**
* #var string
*
* #ORM\Column(name="user_profile_pic", type="string", length=200, nullable=false)
*/
private $userProfilePic = 'uploads/defaults/user/profile_pic.jpg';
/**
* #var string
*
* #ORM\Column(name="user_timeline_pic", type="string", length=200, nullable=false)
*/
private $userTimelinePic = 'uploads/defaults/user/timeline_pic.jpg';
/**
* #var string
*
* #ORM\Column(name="country", type="string", length=50, nullable=false)
*/
private $country;
/**
* #var string
*
* #ORM\Column(name="state", type="string", length=50, nullable=false)
*/
private $state;
/**
* #var string
*
* #ORM\Column(name="city", type="string", length=50, nullable=false)
*/
private $city;
/**
* #var string
*
* #ORM\Column(name="hobbies", type="string", length=100, nullable=false)
*/
private $hobbies;
/**
* #var string
*
* #ORM\Column(name="interests", type="string", length=100, nullable=false)
*/
private $interests;
/**
* #var string
*
* #ORM\Column(name="about", type="string", length=500, nullable=false)
*/
private $about;
/**
* #var boolean
*
* #ORM\Column(name="gender", type="boolean", nullable=false)
*/
private $gender;
/**
* #var \DateTime
*
* #ORM\Column(name="dob", type="date", nullable=false)
*/
private $dob;
/**
* #var integer
*
* #ORM\Column(name="quickblox_id", type="integer", nullable=false)
*/
private $quickbloxId;
/**
* #var boolean
*
* #ORM\Column(name="privacy", type="boolean", nullable=false)
*/
private $privacy = '0';
/**
* #var string
*
* #ORM\Column(name="school", type="string", length=255, nullable=false)
*/
private $school;
/**
* #var string
*
* #ORM\Column(name="college", type="string", length=255, nullable=false)
*/
private $college;
/**
* #var string
*
* #ORM\Column(name="work", type="string", length=255, nullable=false)
*/
private $work;
/**
* #var string
*
* #ORM\Column(name="relationship_status", type="string", length=50, nullable=false)
*/
private $relationshipStatus;
public function getSalt() {
// you *may* need a real salt depending on your encoder
// see section on salt below
return null;
}
public function getRoles() {
return array('ROLE_API');
}
public function eraseCredentials() {
}
/** #see \Serializable::serialize() */
public function serialize() {
return serialize(array(
$this->id,
$this->email,
// see section on salt below
// $this->salt,
));
}
/** #see \Serializable::unserialize() */
public function unserialize($serialized) {
list (
$this->id,
$this->email,
// see section on salt below
// $this->salt
) = unserialize($serialized);
}
/**
* Get id
*
* #return integer
*/
public function getId() {
return $this->id;
}
/**
* Set parentId
*
* #param integer $parentId
* #return Users
*/
public function setParentId($parentId) {
$this->parentId = $parentId;
return $this;
}
/**
* Get parentId
*
* #return integer
*/
public function getParentId() {
return $this->parentId;
}
/**
* Set firstName
*
* #param string $firstName
* #return Users
*/
public function setFirstName($firstName) {
$this->firstName = $firstName;
return $this;
}
/**
* Get firstName
*
* #return string
*/
public function getFirstName() {
return $this->firstName;
}
/**
* Set lastName
*
* #param string $lastName
* #return Users
*/
public function setLastName($lastName) {
$this->lastName = $lastName;
return $this;
}
/**
* Get lastName
*
* #return string
*/
public function getLastName() {
return $this->lastName;
}
/**
* Set userName
*
* #param string $userName
* #return Users
*/
public function setUserName($userName) {
$this->userName = $userName;
return $this;
}
/**
* Get userName
*
* #return string
*/
public function getUserName() {
return $this->email;
}
/**
* Set regType
*
* #param string $regType
* #return Users
*/
public function setRegType($regType) {
$this->regType = $regType;
return $this;
}
/**
* Get regType
*
* #return string
*/
public function getRegType() {
return $this->regType;
}
/**
* Set oauthUid
*
* #param string $oauthUid
* #return Users
*/
public function setOauthUid($oauthUid) {
$this->oauthUid = $oauthUid;
return $this;
}
/**
* Get oauthUid
*
* #return string
*/
public function getOauthUid() {
return $this->oauthUid;
}
/**
* Set active
*
* #param boolean $active
* #return Users
*/
public function setActive($active) {
$this->active = $active;
return $this;
}
/**
* Get active
*
* #return boolean
*/
public function getActive() {
return $this->active;
}
/**
* Set email
*
* #param string $email
* #return Users
*/
public function setEmail($email) {
$this->email = $email;
return $this;
}
/**
* Get email
*
* #return string
*/
public function getEmail() {
return $this->email;
}
/**
* Set password
*
* #param string $password
* #return Users
*/
public function setPassword($password) {
$this->password = $password;
return $this;
}
/**
* Get password
*
* #return string
*/
public function getPassword() {
return $this->password;
}
/**
* Set xmppPassword
*
* #param string $xmppPassword
* #return Users
*/
public function setXmppPassword($xmppPassword) {
$this->xmppPassword = $xmppPassword;
return $this;
}
/**
* Get xmppPassword
*
* #return string
*/
public function getXmppPassword() {
return $this->xmppPassword;
}
/**
* Set createdAt
*
* #param \DateTime $createdAt
* #return Users
*/
public function setCreatedAt($createdAt) {
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* #return \DateTime
*/
public function getCreatedAt() {
return $this->createdAt;
}
/**
* Set updatedAt
*
* #param \DateTime $updatedAt
* #return Users
*/
public function setUpdatedAt($updatedAt) {
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt
*
* #return \DateTime
*/
public function getUpdatedAt() {
return $this->updatedAt;
}
/**
* Set deletedAt
*
* #param \DateTime $deletedAt
* #return Users
*/
public function setDeletedAt($deletedAt) {
$this->deletedAt = $deletedAt;
return $this;
}
/**
* Get deletedAt
*
* #return \DateTime
*/
public function getDeletedAt() {
return $this->deletedAt;
}
/**
* Set activationCode
*
* #param string $activationCode
* #return Users
*/
public function setActivationCode($activationCode) {
$this->activationCode = $activationCode;
return $this;
}
/**
* Get activationCode
*
* #return string
*/
public function getActivationCode() {
return $this->activationCode;
}
/**
* Set userProfilePic
*
* #param string $userProfilePic
* #return Users
*/
public function setUserProfilePic($userProfilePic) {
$this->userProfilePic = $userProfilePic;
return $this;
}
/**
* Get userProfilePic
*
* #return string
*/
public function getUserProfilePic() {
return $this->userProfilePic;
}
/**
* Set userTimelinePic
*
* #param string $userTimelinePic
* #return Users
*/
public function setUserTimelinePic($userTimelinePic) {
$this->userTimelinePic = $userTimelinePic;
return $this;
}
/**
* Get userTimelinePic
*
* #return string
*/
public function getUserTimelinePic() {
return $this->userTimelinePic;
}
/**
* Set country
*
* #param string $country
* #return Users
*/
public function setCountry($country) {
$this->country = $country;
return $this;
}
/**
* Get country
*
* #return string
*/
public function getCountry() {
return $this->country;
}
/**
* Set state
*
* #param string $state
* #return Users
*/
public function setState($state) {
$this->state = $state;
return $this;
}
/**
* Get state
*
* #return string
*/
public function getState() {
return $this->state;
}
/**
* Set city
*
* #param string $city
* #return Users
*/
public function setCity($city) {
$this->city = $city;
return $this;
}
/**
* Get city
*
* #return string
*/
public function getCity() {
return $this->city;
}
/**
* Set hobbies
*
* #param string $hobbies
* #return Users
*/
public function setHobbies($hobbies) {
$this->hobbies = $hobbies;
return $this;
}
/**
* Get hobbies
*
* #return string
*/
public function getHobbies() {
return $this->hobbies;
}
/**
* Set interests
*
* #param string $interests
* #return Users
*/
public function setInterests($interests) {
$this->interests = $interests;
return $this;
}
/**
* Get interests
*
* #return string
*/
public function getInterests() {
return $this->interests;
}
/**
* Set about
*
* #param string $about
* #return Users
*/
public function setAbout($about) {
$this->about = $about;
return $this;
}
/**
* Get about
*
* #return string
*/
public function getAbout() {
return $this->about;
}
/**
* Set gender
*
* #param boolean $gender
* #return Users
*/
public function setGender($gender) {
$this->gender = $gender;
return $this;
}
/**
* Get gender
*
* #return boolean
*/
public function getGender() {
return $this->gender;
}
/**
* Set dob
*
* #param \DateTime $dob
* #return Users
*/
public function setDob($dob) {
$this->dob = $dob;
return $this;
}
/**
* Get dob
*
* #return \DateTime
*/
public function getDob() {
return $this->dob;
}
/**
* Set quickbloxId
*
* #param integer $quickbloxId
* #return Users
*/
public function setQuickbloxId($quickbloxId) {
$this->quickbloxId = $quickbloxId;
return $this;
}
/**
* Get quickbloxId
*
* #return integer
*/
public function getQuickbloxId() {
return $this->quickbloxId;
}
/**
* Set privacy
*
* #param boolean $privacy
* #return Users
*/
public function setPrivacy($privacy) {
$this->privacy = $privacy;
return $this;
}
/**
* Get privacy
*
* #return boolean
*/
public function getPrivacy() {
return $this->privacy;
}
/**
* Set school
*
* #param string $school
* #return Users
*/
public function setSchool($school) {
$this->school = $school;
return $this;
}
/**
* Get school
*
* #return string
*/
public function getSchool() {
return $this->school;
}
/**
* Set college
*
* #param string $college
* #return Users
*/
public function setCollege($college) {
$this->college = $college;
return $this;
}
/**
* Get college
*
* #return string
*/
public function getCollege() {
return $this->college;
}
/**
* Set work
*
* #param string $work
* #return Users
*/
public function setWork($work) {
$this->work = $work;
return $this;
}
/**
* Get work
*
* #return string
*/
public function getWork() {
return $this->work;
}
/**
* Set relationshipStatus
*
* #param string $relationshipStatus
* #return Users
*/
public function setRelationshipStatus($relationshipStatus) {
$this->relationshipStatus = $relationshipStatus;
return $this;
}
/**
* Get relationshipStatus
*
* #return string
*/
public function getRelationshipStatus() {
return $this->relationshipStatus;
}
You can find the answer here https://github.com/Sylius/Sylius/issues/2931.

Symfony2 Error: Attempted to call method on class "Doctrine\Common\Collections\ArrayCollection"

I have a problem with my Symfony project. I ask question on Stack Overflow because everything seems good for me but it's apparently not...
In my project I have a OneToOne bidirectional Doctrine relation between two table named "Visiteur" and "Coordonnees".
My problem appears when I submit my visiteur form. To be clear this form persist some data in "visiteur" table and it persist some data in "coordonnees" table ("imbricated form" translation from French to English)
Then I have the error below :
Attempted to call method "setVisiteur" on class
"Doctrine\Common\Collections\ArrayCollection".
There is my visiteurHandler.php who persist handle my data below.
The error appears in line 54:
$coordonnees->setVisiteur($visiteur);
The line below help me to be sure of my data type :
var_dump(gettype($coordonnees));
I obtain : string(6) "object" which is normal.
namespace Was\RHBundle\Form;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\EntityManager;
use Was\RHBundle\Entity\Visiteur;
use Was\RHBundle\Entity\Coordonnees;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;
class VisiteurHandler
{
protected $form;
protected $request;
protected $em;
public function __construct(Form $form, Request $request, EntityManager $em)
{
$this->form = $form;
$this->request = $request;
$this->em = $em;
}
public function process()
{
if ($this->request->getMethod() == 'POST') {
$this->form->bind($this->request);
if ($this->form->isValid() ) {
// echo '<pre>';
// print_r($this->request);
// echo '</pre>';
// die();
$this->onSuccess($this->form->getData());
return true;
}
}
return false;
}
public function onSuccess(Visiteur $visiteur)
{
$coordonnees=$visiteur->getCoordonnees();
$adresse=$visiteur->getAdresse();
var_dump(gettype($coordonnees));
$coordonnees->setVisiteur($visiteur);
$adresse->setVisiteur($visiteur);
$this->em->persist($coordonnees);
$this->em->persist($adresse);
$visiteur->setCoordonnees($coordonnees);
$visiteur->setAdresse($adresse);
$this->em->persist($visiteur);
$this->em->flush();
}
}
This is my entity visiteur which is my main entity :
<?php
namespace Was\RHBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContext;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Was\RHBundle\Entity\Visiteur
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="Was\RHBundle\Entity\VisiteurRepository")
*
*/
class Visiteur
{
public function __toString()
{
return ucwords($this->prenom . " " . $this->nom);
}
public function __construct()
{
$this->createdAt = new \DateTime();
$this->vehicules = new \Doctrine\Common\Collections\ArrayCollection();
$this->coordonnees = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* #var integer $id
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var datetime $createdAt
*
* #ORM\Column(name="createdAt", type="datetime")
*/
private $createdAt;
/**
* #var string $nom
*
* #ORM\Column(name="nom", type="string", length=255)
*/
private $nom;
/**
* #var string $prenom
*
* #ORM\Column(name="prenom", type="string", length=255)
*/
private $prenom;
/**
* #var date $dateDebut
*
* #ORM\Column(name="dateDebut", type="date")
*/
private $dateDebut;
/**
* #var date $dateFin
*
* #ORM\Column(name="dateFin", type="date")
*/
private $dateFin;
/**
* #var string $service
*
* #ORM\Column(name="service", type="string", length=255)
*/
private $service;
/**
* #var string $fonction
*
* #ORM\Column(name="fonction", type="string", length=255)
*/
private $fonction;
/**
* #var text $remarqueSecurite
*
* #ORM\Column(name="remarqueSecurite", type="text", nullable=true)
*/
private $remarqueSecurite;
/**
* #ORM\OneToMany(targetEntity="Vehicule", mappedBy="visiteur", cascade={"remove"})
*/
private $vehicules;
/**
* #ORM\OneToOne(targetEntity="Was\RHBundle\Entity\Coordonnees", mappedBy="visiteur", cascade={"remove"})
*/
private $coordonnees;
/**
* #ORM\OneToOne(targetEntity="Adresse", mappedBy="visiteur", cascade={"remove"})
*/
private $adresse;
/**
* #ORM\ManyToOne(targetEntity="Agent")
* #ORM\JoinColumn(name="agent_id", referencedColumnName="id", nullable=true)
*/
private $hote;
public function isEnCours()
{
$maintenant = new \DateTime();
if ($maintenant > $this->dateDebut && $maintenant <= $this->dateFin || $this->dateFin == null) return true;
return false;
}
public function isAncien()
{
$maintenant = new \DateTime();
if ($maintenant > $this->dateDebut && $maintenant > $this->dateFin) return true;
return false;
}
public function isFutur()
{
$maintenant = new \DateTime();
if ($maintenant < $this->dateDebut && $maintenant <= $this->dateFin || $this->dateFin == null) return true;
return false;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set nom
*
* #param string $nom
*/
public function setNom($nom)
{
$this->nom = $nom;
}
/**
* Get nom
*
* #return string
*/
public function getNom()
{
return $this->nom;
}
/**
* Set prenom
*
* #param string $prenom
*/
public function setPrenom($prenom)
{
$this->prenom = $prenom;
}
/**
* Get prenom
*
* #return string
*/
public function getPrenom()
{
return $this->prenom;
}
/**
* Set dateDebut
*
* #param date $dateDebut
*/
public function setDateDebut($dateDebut)
{
$this->dateDebut = $dateDebut;
}
/**
* Get dateDebut
*
* #return date
*/
public function getDateDebut()
{
return $this->dateDebut;
}
/**
* Set dateFin
*
* #param date $dateFin
*/
public function setDateFin($dateFin)
{
$this->dateFin = $dateFin;
}
/**
* Get dateFin
*
* #return date
*/
public function getDateFin()
{
return $this->dateFin;
}
/**
* Set service
*
* #param string $service
*/
public function setService($service)
{
$this->service = $service;
}
/**
* Get service
*
* #return string
*/
public function getService()
{
return $this->service;
}
/**
* Set remarqueSecurite
*
* #param text $remarqueSecurite
*/
public function setRemarqueSecurite($remarqueSecurite)
{
$this->remarqueSecurite = $remarqueSecurite;
}
/**
* Get remarqueSecurite
*
* #return text
*/
public function getRemarqueSecurite()
{
return $this->remarqueSecurite;
}
/**
* Add vehicules
*
* #param Was\RHBundle\Entity\Vehicule $vehicules
*/
public function addVehicule(\Was\RHBundle\Entity\Vehicule $vehicules)
{
$this->vehicules[] = $vehicules;
}
/**
* Get vehicules
*
* #return Doctrine\Common\Collections\Collection
*/
public function getVehicules()
{
return $this->vehicules;
}
/**
* Set coordonnees
*
* #param Was\RHBundle\Entity\Coordonnees $coordonnees
*/
public function setCoordonnees(Coordonnees $coordonnees)
{
$this->coordonnees[] = $coordonnees;
//$coordonnees->setVisiteur($this);
//return $this;
}
/**
* Get coordonnees
*
* #return Was\RHBundle\Entity\Coordonnees
*/
public function getCoordonnees()
{
return $this->coordonnees;
}
/**
* Set adresse
*
* #param Was\RHBundle\Entity\Adresse $adresse
*/
public function setAdresse(\Was\RHBundle\Entity\Adresse $adresse)
{
$this->adresse = $adresse;
}
/**
* Get adresse
*
* #return Was\RHBundle\Entity\Adresse
*/
public function getAdresse()
{
return $this->adresse;
}
/**
* Set createdAt
*
* #param datetime $createdAt
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
}
/**
* Get createdAt
*
* #return datetime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set fonction
*
* #param string $fonction
*/
public function setFonction($fonction)
{
$this->fonction = $fonction;
}
/**
* Get fonction
*
* #return string
*/
public function getFonction()
{
return $this->fonction;
}
/**
* Set hote
*
* #param Was\RHBundle\Entity\Agent $hote
*/
public function setHote(\Was\RHBundle\Entity\Agent $hote)
{
$this->hote = $hote;
}
/**
* Get hote
*
* #return Was\RHBundle\Entity\Agent
*/
public function getHote()
{
return $this->hote;
}
/**
* Remove vehicules
*
* #param Was\RHBundle\Entity\Vehicule $vehicules
*/
public function removeVehicule(\Was\RHBundle\Entity\Vehicule $vehicules)
{
$this->vehicules->removeElement($vehicules);
}
}
This my coordonnees Entity :
namespace Was\RHBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Was\UserBundle\Entity\User as User;
/**
* Was\RHBundle\Entity\Coordonnees
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="Was\RHBundle\Entity\CoordonneesRepository")
* #UniqueEntity(fields="emailPro", message="Cet email professionnel est déjà pris.")
*/
class Coordonnees
{
/**
* #var integer $id
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string $telPro
*
* #ORM\Column(name="telPro", type="string", length=255, nullable=true)
*/
private $telPro;
/**
* #var string $telFax
*
* #ORM\Column(name="telFax", type="string", length=255, nullable=true)
*/
private $telFax;
/**
* #var string $telPortable
*
* #ORM\Column(name="telPortable", type="string", length=255, nullable=true)
*/
private $telPortable;
/**
* #var string $telDomicile
*
* #ORM\Column(name="telDomicile", type="string", length=255, nullable=true)
*/
private $telDomicile;
/**
* #var string $telAutre
*
* #ORM\Column(name="telAutre", type="string", length=255, nullable=true)
*/
private $telAutre;
/**
* #var string $telUrgence
*
* #ORM\Column(name="telUrgence", type="string", length=255, nullable=true)
*/
private $telUrgence;
/**
* #ORM\Column(name="contactUrgence", type="text", nullable=true)
*/
private $contactUrgence;
/**
* #ORM\Column(name="contactUrgenceUS", type="text", nullable=true)
*/
private $contactUrgenceUS;
/**
* #var string $numeroBadge
*
* #ORM\Column(name="numeroBadge", type="string", length=255, nullable=true)
*/
private $numeroBadge;
/**
* #ORM\Column(type="string", length=255, nullable=true)
* #Assert\Email(message="Email personnel invalide.")
*/
private $emailPerso;
/**
* #ORM\Column(type="string", length=255, nullable=true)
* #Assert\Email(message="Email professionnel invalide.")
*/
private $emailPro;
/**
* #ORM\OneToOne(targetEntity="Was\RHBundle\Entity\Agent", inversedBy="coordonnees")
* #ORM\JoinColumn( name="agent_id", referencedColumnName="id")
*/
private $agent;
/**
* #ORM\OneToOne(targetEntity="Was\RHBundle\Entity\Visiteur", inversedBy="coordonnees")
* #ORM\JoinColumn(name="visiteur_id", referencedColumnName="id")
*/
private $visiteur;
/**
* #var datetime $updatedAt
*
* #ORM\Column(name="updatedAt", type="datetime", nullable=true)
*/
private $updatedAt;
/**
* #ORM\ManyToOne(targetEntity="\Was\UserBundle\Entity\User")
* #ORM\JoinColumn(name="updated_by_id", referencedColumnName="id", nullable=true)
*/
private $updatedBy;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set telPro
*
* #param string $telPro
*/
public function setTelPro($telPro)
{
$this->telPro = $telPro;
}
/**
* Get telPro
*
* #return string
*/
public function getTelPro()
{
return $this->telPro;
}
/**
* Set telFax
*
* #param string $telFax
*/
public function setTelFax($telFax)
{
$this->telFax = $telFax;
}
/**
* Get telFax
*
* #return string
*/
public function getTelFax()
{
return $this->telFax;
}
/**
* Set telPortable
*
* #param string $telPortable
*/
public function setTelPortable($telPortable)
{
$this->telPortable = $telPortable;
}
/**
* Get telPortable
*
* #return string
*/
public function getTelPortable()
{
return $this->telPortable;
}
/**
* Set telDomicile
*
* #param string $telDomicile
*/
public function setTelDomicile($telDomicile)
{
$this->telDomicile = $telDomicile;
}
/**
* Get telDomicile
*
* #return string
*/
public function getTelDomicile()
{
return $this->telDomicile;
}
/**
* Set telAutre
*
* #param string $telAutre
*/
public function setTelAutre($telAutre)
{
$this->telAutre = $telAutre;
}
/**
* Get telAutre
*
* #return string
*/
public function getTelAutre()
{
return $this->telAutre;
}
/**
* Set telUrgence
*
* #param string $telUrgence
*/
public function setTelUrgence($telUrgence)
{
$this->telUrgence = $telUrgence;
}
/**
* Get telUrgence
*
* #return string
*/
public function getTelUrgence()
{
return $this->telUrgence;
}
/**
* Set agent
*
* #param Was\RHBundle\Entity\Agent $agent
*/
public function setAgent(\Was\RHBundle\Entity\Agent $agent)
{
$this->agent = $agent;
}
/**
* Get agent
*
* #return Was\RHBundle\Entity\Agent
*/
public function getAgent()
{
return $this->agent;
}
/**
* Set emailPerso
*
* #param string $emailPerso
*/
public function setEmailPerso($emailPerso)
{
$this->emailPerso = $emailPerso;
}
/**
* Get emailPerso
*
* #return string
*/
public function getEmailPerso()
{
return $this->emailPerso;
}
/**
* Set emailPro
*
* #param string $emailPro
*/
public function setEmailPro($emailPro)
{
$this->emailPro = $emailPro;
}
/**
* Get emailPro
*
* #return string
*/
public function getEmailPro()
{
return $this->emailPro;
}
/**
* Set visiteur
*
* #param Was\RHBundle\Entity\Visiteur $visiteur
*/
public function setVisiteur(\Was\RHBundle\Entity\Visiteur $visiteur)
{
$this->visiteur = $visiteur;
}
/**
* Get visiteur
*
* #return Was\RHBundle\Entity\Visiteur
*/
public function getVisiteur()
{
return $this->visiteur;
}
/**
* Set updatedAt
*
* #param datetime $updatedAt
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
}
/**
* Get updatedAt
*
* #return datetime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Set updatedBy
*
* #param Was\UserBundle\Entity\User $updatedBy
*/
public function setUpdatedBy($updatedBy)
{
$this->updatedBy = $updatedBy;
}
/**
* Get updatedBy
*
* #return Was\UserBundle\Entity\User
*/
public function getUpdatedBy()
{
return $this->updatedBy;
}
/**
* Set numeroBadge
*
* #param string $numeroBadge
*/
public function setNumeroBadge($numeroBadge)
{
$this->numeroBadge = $numeroBadge;
}
/**
* Get numeroBadge
*
* #return string
*/
public function getNumeroBadge()
{
return $this->numeroBadge;
}
/**
* Set contactUrgence
*
* #param text $contactUrgence
*/
public function setContactUrgence($contactUrgence)
{
$this->contactUrgence = $contactUrgence;
}
/**
* Get contactUrgence
*
* #return text
*/
public function getContactUrgence()
{
return $this->contactUrgence;
}
/**
* Set contactUrgenceUS
*
* #param text $contactUrgenceUS
*/
public function setContactUrgenceUS($contactUrgenceUS)
{
$this->contactUrgenceUS = $contactUrgenceUS;
}
/**
* Get contactUrgenceUS
*
* #return text
*/
public function getContactUrgenceUS()
{
return $this->contactUrgenceUS;
}
}
You say (and define it with annotations) that it's a OneToOne relation.
But look in to Visiteur entity class.
You set cordonnees to be an ArrayCollection instead of single Coordonness entity object in constructor.
public function __construct()
{
$this->createdAt = new \DateTime();
$this->vehicules = new \Doctrine\Common\Collections\ArrayCollection();
$this->coordonnees = new \Doctrine\Common\Collections\ArrayCollection(); // <-- here
}
And futher in setter you use it as an array too:
/**
* Set coordonnees
*
* #param Was\RHBundle\Entity\Coordonnees $coordonnees
*/
public function setCoordonnees(Coordonnees $coordonnees)
{
$this->coordonnees[] = $coordonnees;
//$coordonnees->setVisiteur($this);
//return $this;
}
So the getter returns an array (ArrayCollection object actually) of entities.
Let's look at the problematic code:
public function onSuccess(Visiteur $visiteur)
{
$coordonnees=$visiteur->getCoordonnees(); //this returns ArrayCollection of Coordnnees entity objects
$adresse=$visiteur->getAdresse();
var_dump(gettype($coordonnees)); // yes, it says "object" because it's instance of ArrayCollection class
$coordonnees->setVisiteur($visiteur); //Now you should know, why it won't work. It's not an entity object, but ArrayCollection of entity objects.
//(...)
}
I think that $coordonneess shoudn't be an ArrayCollection since it's OneToOne relation.

symfony 2 how to create or map entity in different bundles

I have project which have different bundles. I want to create or divide entities in different bundle how can I create this. I am new in symfony please help me . I created but I can not do mapping correctly . a table which have primary key can't use in another bundle.
Here is my Entity
namespace DomainBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* WebsiteDomainConfigTest
*
* #ORM\Table(name="website_domain_config_test", indexes={#ORM\Index(name="fk_website_domain_config_test_1_idx", columns={"vendor_id"}), #ORM\Index(name="fk_website_domain_config_test_2_idx", columns={"country_id"})})
* #ORM\Entity
*/
class WebsiteDomainConfigTest
{
/**
* #var string
*
* #ORM\Column(name="domain", type="string", length=255, nullable=true)
*/
private $domain;
/**
* #var string
*
* #ORM\Column(name="vendor_code", type="string", length=15, nullable=true)
*/
private $vendorCode;
/**
* #var string
*
* #ORM\Column(name="domain_path", type="string", length=255, nullable=true)
*/
private $domainPath;
/**
* #var string
*
* #ORM\Column(name="assets_path", type="string", length=45, nullable=true)
*/
private $assetsPath;
/**
* #var string
*
* #ORM\Column(name="language", type="string", length=3, nullable=true)
*/
private $language;
/**
* #var string
*
* #ORM\Column(name="affiliate", type="string", length=25, nullable=true)
*/
private $affiliate;
/**
* #var string
*
* #ORM\Column(name="affiliate_logo", type="string", length=255, nullable=true)
*/
private $affiliateLogo;
/**
* #var string
*
* #ORM\Column(name="affiliate_address", type="string", length=255, nullable=true)
*/
private $affiliateAddress;
/**
* #var integer
*
* #ORM\Column(name="status", type="integer", nullable=true)
*/
private $status;
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var \MobileSplash\SplashRequestBundle\Entity\Countries
*
* #ORM\ManyToOne(targetEntity="MobileSplash\SplashRequestBundle\Entity\Countries")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="country_id", referencedColumnName="id")
* })
*/
private $country;
/**
* #var \MobileSplash\SplashRequestBundle\Entity\Vendors
*
* #ORM\ManyToOne(targetEntity="MobileSplash\SplashRequestBundle\Entity\Vendors")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="vendor_id", referencedColumnName="id")
* })
*/
private $vendor;
/**
* Set domain
*
* #param string $domain
* #return WebsiteDomainConfigTest
*/
public function setDomain($domain)
{
$this->domain = $domain;
return $this;
}
/**
* Get domain
*
* #return string
*/
public function getDomain()
{
return $this->domain;
}
/**
* Set vendorCode
*
* #param string $vendorCode
* #return WebsiteDomainConfigTest
*/
public function setVendorCode($vendorCode)
{
$this->vendorCode = $vendorCode;
return $this;
}
/**
* Get vendorCode
*
* #return string
*/
public function getVendorCode()
{
return $this->vendorCode;
}
/**
* Set domainPath
*
* #param string $domainPath
* #return WebsiteDomainConfigTest
*/
public function setDomainPath($domainPath)
{
$this->domainPath = $domainPath;
return $this;
}
/**
* Get domainPath
*
* #return string
*/
public function getDomainPath()
{
return $this->domainPath;
}
/**
* Set assetsPath
*
* #param string $assetsPath
* #return WebsiteDomainConfigTest
*/
public function setAssetsPath($assetsPath)
{
$this->assetsPath = $assetsPath;
return $this;
}
/**
* Get assetsPath
*
* #return string
*/
public function getAssetsPath()
{
return $this->assetsPath;
}
/**
* Set language
*
* #param string $language
* #return WebsiteDomainConfigTest
*/
public function setLanguage($language)
{
$this->language = $language;
return $this;
}
/**
* Get language
*
* #return string
*/
public function getLanguage()
{
return $this->language;
}
/**
* Set affiliate
*
* #param string $affiliate
* #return WebsiteDomainConfigTest
*/
public function setAffiliate($affiliate)
{
$this->affiliate = $affiliate;
return $this;
}
/**
* Get affiliate
*
* #return string
*/
public function getAffiliate()
{
return $this->affiliate;
}
/**
* Set affiliateLogo
*
* #param string $affiliateLogo
* #return WebsiteDomainConfigTest
*/
public function setAffiliateLogo($affiliateLogo)
{
$this->affiliateLogo = $affiliateLogo;
return $this;
}
/**
* Get affiliateLogo
*
* #return string
*/
public function getAffiliateLogo()
{
return $this->affiliateLogo;
}
/**
* Set affiliateAddress
*
* #param string $affiliateAddress
* #return WebsiteDomainConfigTest
*/
public function setAffiliateAddress($affiliateAddress)
{
$this->affiliateAddress = $affiliateAddress;
return $this;
}
/**
* Get affiliateAddress
*
* #return string
*/
public function getAffiliateAddress()
{
return $this->affiliateAddress;
}
/**
* Set status
*
* #param integer $status
* #return WebsiteDomainConfigTest
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* Get status
*
* #return integer
*/
public function getStatus()
{
return $this->status;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set country
*
* #param \MobileSplash\SplashRequestBundle\Entity\Countries $country
* #return WebsiteDomainConfigTest
*/
public function setCountry(\MobileSplash\SplashRequestBundle\Entity\Countries $country = null)
{
$this->country = $country;
return $this;
}
/**
* Get country
*
* #return \MobileSplash\SplashRequestBundle\Entity\Countries
*/
public function getCountry()
{
return $this->country;
}
/**
* Set vendor
*
* #param \MobileSplash\SplashRequestBundle\Entity\Vendors $vendor
* #return WebsiteDomainConfigTest
*/
public function setVendor(\MobileSplash\SplashRequestBundle\Entity\Vendors $vendor = null)
{
$this->vendor = $vendor;
return $this;
}
/**
* Get vendor
*
* #return \MobileSplash\SplashRequestBundle\Entity\Vendors
*/
public function getVendor()
{
return $this->vendor;
}
}
in your annotation use namespace like this:
targetEntity="\Mj\FooBundle\Entity\Foo"

Symfony2 - a User references a roles entity by id but i can't retrieve the user rol when i log in

This is my user entity
<?php
namespace Monse\UsuariosBundle\Entity;
use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* Monse\UsuariosBundle\Entity\Usuario
*
* #ORM\Table(name="users")
* #ORM\Entity
*/
class Usuario implements UserInterface
{
/**
* #var integer $id
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #ORM\OneToOne(targetEntity="Monse\ClientesBundle\Entity\Cliente")
* #ORM\JoinColumn(name="cliente_id", referencedColumnName="id",nullable=true)
*/
protected $cliente;
/**
* #var string $usuario
*
* #ORM\Column(name="usuario", type="string", length=255, unique=true)
*/
protected $usuario;
/**
* #var string $email
*
* #ORM\Column(name="email", type="string", length=255, unique=true)
*/
protected $email;
/**
* #var string $password
*
* #ORM\Column(name="password", type="string", length=255)
*/
protected $password;
/**
* #var string $salt
*
* #ORM\Column(name="salt", type="string", length=255)
*/
protected $salt;
/**
* #var date $ultimo_ingreso
*
* #ORM\Column(name="ultimo_ingreso", type="date")
*/
protected $ultimo_ingreso;
/**
* #var date $fecha_alta
*
* #ORM\Column(name="fecha_alta", type="date")
*/
protected $fecha_alta;
/**
* #ORM\ManyToOne(targetEntity="Monse\UsuariosBundle\Entity\Rol")
* #ORM\JoinColumn(name="rol", referencedColumnName="id",nullable=false)
*/
protected $rol;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
public function setCliente(\Monse\ClientesBundle\Entity\Cliente $cliente)
{
$this->cliente = $cliente;
}
/**
* Get cliente
*
* #return integer
*/
public function getCliente()
{
return $this->cliente;
}
/**
* Set usuario
*
* #param string $usuario
*/
public function setUsuario($usuario)
{
$this->usuario = $usuario;
}
/**
* Get usuario
*
* #return string
*/
public function getUsuario()
{
return $this->usuario;
}
/**
* Set email
*
* #param string $email
*/
public function setEmail($email)
{
$this->email = $email;
}
/**
* Get email
*
* #return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set contrasena
*
* #param string $contrasena
*/
public function setPassword($password)
{
$this->password = $password;
}
/**
* Get contrasena
*
* #return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set salt
*
* #param string $salt
*/
public function setSalt($salt)
{
$this->salt = $salt;
}
/**
* Get salt
*
* #return string
*/
public function getSalt()
{
return $this->salt;
}
/**
* Set ultimo_ingreso
*
* #param date $ultimoIngreso
*/
public function setUltimoIngreso($ultimoIngreso)
{
$this->ultimo_ingreso = $ultimoIngreso;
}
/**
* Get ultimo_ingreso
*
* #return date
*/
public function getUltimoIngreso()
{
return $this->ultimo_ingreso;
}
/**
* Set fecha_alta
*
* #param date $fechaAlta
*/
public function setFechaAlta($fechaAlta)
{
$this->fecha_alta = $fechaAlta;
}
/**
* Get fecha_alta
*
* #return date
*/
public function getFechaAlta()
{
return $this->fecha_alta;
}
/**
* Set rol
*
* #param integer $rol
*/
public function setRol(\Monse\UsuariosBundle\Entity\Rol $rol)
{
$this->rol = $rol;
}
/**
* Get rol
*
* #return integer
*/
public function getRol()
{
return $this->rol;
}
public function __construct()
{
$this->fecha_alta = new \DateTime();
}
function equals(\Symfony\Component\Security\Core\User\UserInterface $usuario)
{
return $this->getUsuario() == $usuario->getUsername();
}
function eraseCredentials()
{
}
function getRoles()
{
}
function getUsername()
{
return $this->getUsuario();
}
}
and this is my roles entity
<?php
namespace Monse\UsuariosBundle\Entity;
use Symfony\Component\Security\Core\Role\RoleInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* Monse\UsuariosBundle\Entity\Rol
*
* #ORM\Table(name="roles")
* #ORM\Entity
*/
class Rol implements RoleInterface
{
/**
* #var integer $id
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #var string $role
*
* #ORM\Column(name="rol", type="string", length=255)
*/
protected $role;
/**
* #var string $denominacion
*
* #ORM\Column(name="denominacion", type="string", length=255)
*/
protected $denominacion;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set rol
*
* #param string $rol
*/
public function setRole($role)
{
$this->role = $role;
}
/**
* Get rol
*
* #return string
*/
public function getRole()
{
return $this->role;
}
public function setDenominacion($denominacion)
{
$this->denominacion = $denominacion;
}
/**
* Get denominacion
*
* #return string
*/
public function getDenominacion()
{
return $this->denominacion;
}
public function __toString() {
return $this->denominacion;
}
}
Please HELP, i don't know what i'm doing wrong?
I need to administrate ROLES, that's why i have the entity.
In the Rol entity
rol has ROLE_ADMIN, ROLE_USER...
denominacion is Super Admin, Admin, User, etc...
I need to retreive ROL
Function getRoles() in Usuario should return an array of role names. Why yours is empty?
public function getRoles()
{
return $this->roles->map(function($r) { return $r->getRole(); })
->toArray();
}
Usuario has a many to one relation with role. Are you sure this is correct? The above example assumes that you have a collection of roles.

Categories