I'm working on a Symfony2.5 project with FOSUserBundle and I need to add the ability to create users profile from the same register form. Right now I have two entities SysUsuario
and SysPerfil
. This is the code for SysUsuario
:
class SysUsuario extends BaseUser
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToMany(targetEntity="SysGrupos")
* @ORM\JoinTable(name="sys_usuarios_grupos",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}
* )
*/
protected $groups;
}
And this is the code (relevant part just the attributes) for SysPerfil
:
class SysPerfil
{
/**
* @var integer
*
* @ORM\Column(name="idperfil", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $idperfil;
/**
* @var string
*
* @ORM\Column(name="pers_juridica", type="string", length=1, nullable=false)
*/
protected $persJuridica = 'V';
/**
* @var boolean
*
* @ORM\Column(name="rif", type="boolean", nullable=false)
*/
protected $rif;
/**
* @var boolean
*
* @ORM\Column(name="ci", type="boolean", nullable=false)
*/
protected $ci;
/**
* @var string
*
* @ORM\Column(name="nombre", type="string", length=50, nullable=true)
*/
protected $nombre;
/**
* @var string
*
* @ORM\Column(name="apellido", type="string", length=50, nullable=true)
*/
protected $apellido;
/**
* @ORM\ManyToOne(targetEntity="SysUsuario")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="user", referencedColumnName="id")
* })
*/
protected $user;
}
I have created also two Form: UsuarioType
and PerfilType
:
UsuarioType
class UsuarioType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder
->add('perfil', new PerfilType())
->add('email', 'email', array(
'required' => true,
'label' => 'Email',
'trim' => true
))
->add('password', 'password', array(
'required' => true,
'label' => 'Contraseña',
'always_empty' => true
))
->add('confirm', 'password', array(
'required' => true,
'mapped' => false,
'label' => 'Verificar contraseña',
'always_empty' => true
));
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(
array(
'data_class' => 'Sunahip\UserBundle\Entity\SysUsuario',
'intention' => 'new_user'
)
);
}
public function getName()
{
return 'user_register';
}
}
PerfilType
class PerfilType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder
->add('persJuridica', 'choice', array(
'choices' => array('0' => 'V', '1' => 'J'),
'required' => true,
'label' => 'RIF',
'trim' => true
))
->add('rif', 'text', array(
'required' => true,
'label' => false,
'trim' => true
))
->add('ci', 'text', array(
'required' => true,
'label' => 'CI',
'trim' => true
))
->add('nombre', 'text', array(
'required' => true,
'label' => 'Nombre',
'trim' => true
))
->add('apellido', 'text', array(
'required' => true,
'label' => 'Apellidos',
'trim' => true
));
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(
array(
'data_class' => 'Sunahip\UserBundle\Entity\SysPerfil',
'intention' => 'new_user_profile'
)
);
}
public function getName()
{
return 'user_profile';
}
}
But I'm getting this error:
Neither the property "perfil" nor one of the methods "getPerfil()", "perfil()", "isPerfil()", "hasPerfil()", "__get()" exist and have public access in class "Sunahip\UserBundle\Entity\SysUsuario".
What's wrong on my approach? How did yours do this?