我在Symfony 2.7.9上收到此错误:
属性“puestos”和“addPuesto()”/“removePuesto()”,“setPuestos()”,“puestos()”,“__ set()”或“__call()”方法之一都不存在并在“UserBundle \ Entity \ UsuarioTrabajador”课程中公开访问。
<?php
namespace UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use PUGX\MultiUserBundle\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity
* @ORM\Table(name="usuario_trabajador")
* @UniqueEntity(fields = "username", targetClass = "UserBundle\Entity\Usuario", message="fos_user.username.already_used")
* @UniqueEntity(fields = "email", targetClass = "UserBundle\Entity\Usuario", message="fos_user.email.already_used")
*
* @UniqueEntity(fields = {"nit","dpi"}, targetClass = "UserBundle\Entity\UsuarioTrabajador", message="El dpi o nit debe ser único")
* Esta entidad cubre los tipos de Asistente, Supervisor y Gerente.
*
* @author Pablo Díaz soporte@newtonlabs.com.gt
*/
class UsuarioTrabajador extends Usuario
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
* @ORM\Column(name="direccion",type="string",length=255)
*/
private $direccion;
/**
* @var date fecha de egreso de la empresa.
* @ORM\Column(name="fechaEgreso", type="date",nullable=true)
*/
private $fechaEgreso;
/**
* @var string DPI del trabajador
* @ORM\Column(name="dpi",type="string",length=20, unique=true)
*/
private $dpi;
/**
* Número de identificación tributaria.
*
* @var string
* @ORM\Column(name="nit", type="string",length=20,unique=true)
*/
private $nit;
/**
* @var int
* @ORM\Column(name="telefono", type="string",length=15,nullable=true)
*/
private $telefono;
/**
* @var ArrayCollection
* @ORM\OneToMany(targetEntity="DatosPrestaciones", mappedBy="usuario")
*/
private $datosPrestaciones;
/**
* @var string Tipo de Usuarios(Asistente, Supervisor, Gerente)
* @ORM\OneToMany(targetEntity="UserBundle\Entity\Puesto", mappedBy="usuarioPuesto")
*/
private $puestos;
/**
* Constructor.
*/
public function __construct()
{
$this->datosPrestaciones = new \Doctrine\Common\Collections\ArrayCollection();
$this->puestos = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Set direccion
*
* @param string $direccion
*
* @return UsuarioTrabajador
*/
public function setDireccion($direccion)
{
$this->direccion = $direccion;
return $this;
}
/**
* Get direccion
*
* @return string
*/
public function getDireccion()
{
return $this->direccion;
}
/**
* Set fechaEgreso
*
* @param \DateTime $fechaEgreso
*
* @return UsuarioTrabajador
*/
public function setFechaEgreso($fechaEgreso)
{
$this->fechaEgreso = $fechaEgreso;
return $this;
}
/**
* Get fechaEgreso
*
* @return \DateTime
*/
public function getFechaEgreso()
{
return $this->fechaEgreso;
}
/**
* Set dpi
*
* @param string $dpi
*
* @return UsuarioTrabajador
*/
public function setDpi($dpi)
{
$this->dpi = $dpi;
return $this;
}
/**
* Get dpi
*
* @return string
*/
public function getDpi()
{
return $this->dpi;
}
/**
* Set nit
*
* @param string $nit
*
* @return UsuarioTrabajador
*/
public function setNit($nit)
{
$this->nit = $nit;
return $this;
}
/**
* Get nit
*
* @return string
*/
public function getNit()
{
return $this->nit;
}
/**
* Set telefono
*
* @param string $telefono
*
* @return UsuarioTrabajador
*/
public function setTelefono($telefono)
{
$this->telefono = $telefono;
return $this;
}
/**
* Get telefono
*
* @return string
*/
public function getTelefono()
{
return $this->telefono;
}
/**
* Add datosPrestacione
*
* @param \UserBundle\Entity\DatosPrestaciones $datosPrestacione
*
* @return UsuarioTrabajador
*/
public function addDatosPrestacione(\UserBundle\Entity\DatosPrestaciones $datosPrestacione)
{
$this->datosPrestaciones[] = $datosPrestacione;
return $this;
}
/**
* Remove datosPrestacione
*
* @param \UserBundle\Entity\DatosPrestaciones $datosPrestacione
*/
public function removeDatosPrestacione(\UserBundle\Entity\DatosPrestaciones $datosPrestacione)
{
$this->datosPrestaciones->removeElement($datosPrestacione);
}
/**
* Get datosPrestaciones
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getDatosPrestaciones()
{
return $this->datosPrestaciones;
}
/**
* Add puesto
*
* @param \UserBundle\Entity\Puesto $puesto
*
* @return UsuarioTrabajador
*/
public function addPuesto(\UserBundle\Entity\Puesto $puesto)
{
$this->puestos[] = $puesto;
return $this;
}
/**
* Remove puesto
*
* @param \UserBundle\Entity\Puesto $puesto
*/
public function removePuesto(\UserBundle\Entity\Puesto $puesto)
{
$this->puestos->removeElement($puesto);
}
/**
* Get puestos
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getPuestos()
{
return $this->puestos;
}
public function __toString()
{
return $this->nombre.' '.$this->apellidos;
}
}
这是另一个实体
<?php
namespace UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Puesto
*
* @ORM\Table()
* @ORM\Entity
*/
class Puesto
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="tipoPuesto",type="string",length=100)
*/
private $tipoPuesto;
/**
* @var string
*
* @ORM\Column(name="nombrePuesto", type="string", length=255)
*/
private $nombrePuesto;
/**
* @var \DateTime
*
* @ORM\Column(name="date", type="date")
*/
private $date;
/**
* @ORM\ManyToOne(targetEntity="UserBundle\Entity\UsuarioTrabajador", inversedBy="puestos")
* @var [type]
*/
private $usuarioPuesto;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set nombrePuesto
*
* @param string $nombrePuesto
*
* @return Puesto
*/
public function setNombrePuesto($nombrePuesto)
{
$this->nombrePuesto = $nombrePuesto;
return $this;
}
/**
* Get nombrePuesto
*
* @return string
*/
public function getNombrePuesto()
{
return $this->nombrePuesto;
}
/**
* Set date
*
* @param \DateTime $date
*
* @return Puesto
*/
public function setDate($date)
{
$this->date = $date;
return $this;
}
/**
* Get date
*
* @return \DateTime
*/
public function getDate()
{
return $this->date;
}
/**
* Set usuario
*
* @param \UserBundle\Entity\UsuarioTrabajdor $usuario
*
* @return Puesto
*/
public function setUsuario(\UserBundle\Entity\UsuarioTrabajdor $usuario = null)
{
$this->usuario = $usuario;
return $this;
}
/**
* Get usuario
*
* @return \UserBundle\Entity\UsuarioTrabajdor
*/
public function getUsuario()
{
return $this->usuario;
}
/**
* Set tipoPuesto
*
* @param string $tipoPuesto
*
* @return Puesto
*/
public function setTipoPuesto($tipoPuesto)
{
$this->tipoPuesto = $tipoPuesto;
return $this;
}
/**
* Get tipoPuesto
*
* @return string
*/
public function getTipoPuesto()
{
return $this->tipoPuesto;
}
/**
* Mostrar el noombre del puesto
* @return string
*/
public function __toString()
{
return $this->tipoPuesto.': '.$this->nombrePuesto.' '.$this->getUsuarioPuesto();
}
/**
* Set usuarioPuesto
*
* @param \UserBundle\Entity\UsuarioTrabajador $usuarioPuesto
*
* @return Puesto
*/
public function setUsuarioPuesto(\UserBundle\Entity\UsuarioTrabajador $usuarioPuesto = null)
{
$this->usuarioPuesto = $usuarioPuesto;
return $this;
}
/**
* Get usuarioPuesto
*
* @return \UserBundle\Entity\UsuarioTrabajador
*/
public function getUsuarioPuesto()
{
return $this->usuarioPuesto;
}
}
这是表格
<?php
namespace UserBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
class RegistrationTrabajadorFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
// agregar campos personalizados
$builder->add('nombre', null, [
'label' => 'Nombre/s',
'attr' => [
'placeholder' => 'Nombre/s',
'class' => 'form-control input-lg',
],
])
->add('apellidos', null, [
'label' => 'Apellidos/s',
'attr' => [
'placeholder' => 'Apellidos',
'class' => 'form-control input-lg',
],
])
->add('username', null, [
'label' => 'Usuario',
'translation_domain' => 'FOSUserBundle',
'attr' => [
'class' => 'form-control input-lg',
'placeholder' => 'Nombre de Usuario',
],
])
->add('email', 'email', [
'label' => 'Correo',
'translation_domain' => 'FOSUserBundle',
'required' => true,
'attr' => [
'class' => 'form-control input-lg',
'placeholder' => 'Correo electrónico',
],
])
->add('plainPassword', 'repeated', [
'label' => 'Contraseña',
'type' => 'password',
'options' => ['translation_domain' => 'FOSUserBundle'],
'first_options' => [
'label' => 'Contraseña',
'attr' => [
'class' => 'form-control input-lg',
'placeholder' => 'Contraseña',
],
],
'second_options' => [
'label' => 'Repetir Contraseña',
'attr' => [
'class' => 'form-control input-lg',
'placeholder' => 'Repetir Contraseña',
],
],
'invalid_message' => 'fos_user.password.mismatch',
])
->add('direccion',null,[
'label' => 'Dirección',
'attr' => [
'class' => 'form-control input-lg',
'placeholder' => 'Dirección',
],
'required' => true,
])
->add('dpi', null, [
'label' => 'DPI',
'attr' => [
'class' => 'form-control input-lg',
'placeholder' => 'Documento Personal de Identificación',
],
'required' => true,
])
->add('nit', null, [
'label' => 'NIT',
'attr' => [
'class' => 'form-control input-lg',
'placeholder' => 'Número de Identificación Tributaria',
],
'required' => true,
])
->add('telefono', null, [
'label' => 'Teléfono',
'translation_domain' => 'FOSUserBundle',
'attr' => [
'class' => 'form-control input-lg',
'placeholder' => 'Teléfono',
],
'required' => false,
])
->add('submit', 'submit', [
'label' => 'Guardar',
'attr' => [
'class' => 'btn btn-primary',
],
])
->add('puestos', 'entity', [
'label' => false,
'empty_value' => 'Aquí aparecerá su puesto',
'class' => 'UserBundle:Puesto',
'attr' => [
'class' => 'select2',
],
])
;
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'validation' => ['registration'],
]);
}
public function getParent()
{
return 'fos_user_registration';
}
public function getName()
{
return 'user_registration';
}
}