我有这个实体(Registro):
<?php
namespace GitekRegistroBundleEntity;
use DoctrineORMMapping as ORM;
/**
* GitekRegistroBundleEntityRegistro
*
* @ORMTable()
* @ORMEntity(repositoryClass="GitekRegistroBundleEntityRegistroRepository"))
*/
class Registro
{
/**
* @var integer $id
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var datetime $fecha
*
* @ORMColumn(name="fecha", type="datetime")
*/
private $fecha;
/**
* @var smallint $comenzado
*
* @ORMColumn(name="comenzado", type="smallint", nullable=true)
*/
private $comenzado;
/**
* @var smallint $completado
*
* @ORMColumn(name="completado", type="smallint", nullable=true)
*/
private $completado;
/**
* @var datetime $created_at
*
* @ORMColumn(name="created_at", type="datetime")
*/
private $created_at;
/**
* @var datetime $updated_at
*
* @ORMColumn(name="updated_at", type="datetime")
*/
private $updated_at;
/** @ORMManyToOne(targetEntity="GitekUsuarioBundleEntityUsuario") */
protected $usuario;
/** @ORMManyToOne(targetEntity="GitekHotelBundleEntityTipotarea") */
protected $tipotarea;
/** @ORMManyToOne(targetEntity="GitekHotelBundleEntityHabitacion") */
protected $habitacion;
/** @ORMManyToOne(targetEntity="GitekRegistroBundleEntityMaster") */
protected $master;
/**
* @ORMManyToMany(targetEntity="GitekHotelBundleEntityIncidencia", inversedBy="registros")
* @ORMJoinTable(name="incidencia_registro",
* joinColumns={@ORMJoinColumn(name="registro_id", referencedColumnName="id")},
* inverseJoinColumns={@ORMJoinColumn(name="incidencia_id", referencedColumnName="id")}
* )
*/
protected $incidencias;
public function __construct()
{
$this->created_at = new DateTime();
$this->updated_at = new DateTime();
}
// public function __toString()
// {
// return $this->getNombre();
// }
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set fecha
*
* @param datetime $fecha
*/
public function setFecha($fecha)
{
$this->fecha = $fecha;
}
/**
* Get fecha
*
* @return datetime
*/
public function getFecha()
{
return $this->fecha;
}
/**
* Set comenzado
*
* @param smallint $comenzado
*/
public function setComenzado($comenzado)
{
$this->comenzado = $comenzado;
}
/**
* Get comenzado
*
* @return smallint
*/
public function getComenzado()
{
return $this->comenzado;
}
/**
* Set completado
*
* @param smallint $completado
*/
public function setCompletado($completado)
{
$this->completado = $completado;
}
/**
* Get completado
*
* @return smallint
*/
public function getCompletado()
{
return $this->completado;
}
/**
* Set created_at
*
* @param datetime $createdAt
*/
public function setCreatedAt($createdAt)
{
$this->created_at = $createdAt;
}
/**
* Get created_at
*
* @return datetime
*/
public function getCreatedAt()
{
return $this->created_at;
}
/**
* Set updated_at
*
* @param datetime $updatedAt
*/
public function setUpdatedAt($updatedAt)
{
$this->updated_at = $updatedAt;
}
/**
* Get updated_at
*
* @return datetime
*/
public function getUpdatedAt()
{
return $this->updated_at;
}
/**
* Set usuario
*
* @param GitekUsuarioBundleEntityUsuario $usuario
*/
public function setUsuario(GitekUsuarioBundleEntityUsuario $usuario)
{
$this->usuario = $usuario;
}
/**
* Get usuario
*
* @return GitekUsuarioBundleEntityUsuario
*/
public function getUsuario()
{
return $this->usuario;
}
/**
* Set tipotarea
*
* @param GitekHotelBundleEntityTipotarea $tipotarea
*/
public function setTipotarea(GitekHotelBundleEntityTipotarea $tipotarea)
{
$this->tipotarea = $tipotarea;
}
/**
* Get tipotarea
*
* @return GitekHotelBundleEntityTipotarea
*/
public function getTipotarea()
{
return $this->tipotarea;
}
/**
* Set habitacion
*
* @param GitekHotelBundleEntityHabitacion $habitacion
*/
public function setHabitacion(GitekHotelBundleEntityHabitacion $habitacion)
{
$this->habitacion = $habitacion;
}
/**
* Get habitacion
*
* @return GitekHotelBundleEntityHabitacion
*/
public function getHabitacion()
{
return $this->habitacion;
}
/**
* Add incidencias
*
* @param GitekHotelBundleEntityIncidencia $incidencias
*/
public function addIncidencia(GitekHotelBundleEntityIncidencia $incidencias)
{
$this->incidencias[] = $incidencias;
}
/**
* Get incidencias
*
* @return DoctrineCommonCollectionsCollection
*/
public function getIncidencias()
{
return $this->incidencias;
}
}
我想一劳永逸地节省多份数据,因此我设立了一个新的实体,只有像现在这样一阵列:
<?php
namespace GitekRegistroBundleEntity;
use DoctrineCommonCollectionsArrayCollection;
use DoctrineORMMapping as ORM;
class Master
{
/** @ORMOneToMany(targetEntity="GitekHotelBundleEntityHabitacion", mappedBy="master") */
protected $registros;
public function __construct()
{
$this->registros = new ArrayCollection();
}
public function getRegistros()
{
return $this->registros;
}
public function setRegistros(ArrayCollection $registros)
{
$this->registros = $registros;
}
}
我创立了我的大通布。
<?php
namespace GitekRegistroBundleForm;
use SymfonyComponentFormAbstractType;
use SymfonyComponentFormFormBuilder;
use DoctrineORMEntityRepository;
class MasterType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add( registros , collection , array(
type => new RegistroType(),
allow_add => true,
by_reference => true,
));
}
public function getDefaultOptions(array $options)
{
return array(
data_class => GitekRegistroBundleEntityMaster
);
}
public function getName()
{
return master ;
}
}
这是我的控制者:
public function asignarAction()
{
$master = new Master();
$request = $this->getRequest();
$form = $this->createForm(new MasterType(), $master);
if ( POST === $request->getMethod()) {
$form->bindRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getEntityManager();
$em->persist($master);
$em->flush();
return $this->redirect($this->generateUrl( recepcion_asignar ));
}else {
print_r("ezez");
print_r($form->getErrors());
}
} else {
}
return $this->render( RegistroBundle:Recepcion:asignar.html.twig , array(
registro => $master,
form => $form->createView()
));
}
表格显示,我看到数据正确提交,但数据并非始终存在,因此,我总是在以下时间发现这一错误:
Class GitekRegistroBundleEntityMaster is not a valid entity or mapped super class.
I think that the problem is within de Master entity.
任何帮助或cl?