好吧,我在使用composedObject时遇到问题,在OneToMany关系中,编辑表单没有呈现我的实体的值,我认为这是因为我的另一个类返回了一个集合
这是我的第一个类,包含我的合成对象
<?php
namespace NominaEntityEmpleado;
use DoctrineCommonCollectionsArrayCollection;
use DoctrineORMMapping as ORM;
use ZendFormAnnotation;
/**
* Empleado2
*
* @ORMTable(name="empleado2")
* @ORMEntity
* @AnnotationHydrator("ZendStdlibHydratorObjectProperty")
* @AnnotationName("EmpleadoForm")
*/
class Empleado2
{
/**
* @var integer
*
* @ORMColumn(name="id", type="integer", nullable=false)
* @ORMId
* @ORMGeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORMColumn(name="nombre", type="string", length=255, nullable=true)
* @AnnotationType("ZendFormElementText")
* @AnnotationRequired({"required":"true"})
* @AnnotationFilter({"name":"StripTags"})
* @AnnotationOptions({"label":"Numero de empleado"})
* @AnnotationAttributes({"class":"form-control"})
*/
private $nombre;
/**
* @ORMOneToMany(targetEntity="NominaEntityEmpleadoEmpleadoDetalles2", mappedBy="empleado")
* @AnnotationComposedObject("NominaEntityEmpleadoEmpleadoDetalles2",is_collection=true,options={"count":1})
*/
private $detalles;
/**
* AnnotationComposedObject("NominaEntityEmpleadoEmpleadoDetalles2")
*/
private $detalle;
/**
* @AnnotationType("ZendFormElementSubmit")
* @AnnotationAttributes({"value":"Procesar"})
* @AnnotationAttributes({"class":"btn btn-primary"})
*/
public $submit;
public function __construct()
{
$this->detalles = new ArrayCollection();
}
public function addDetalles(Collection $detalles)
{
foreach ($detalles as $detalle) {
$detalle->setEmpleado($this);
$this->detalles->add($detalle);
}
}
public function removeDetalles(Collection $detalles)
{
foreach ($detalles as $detalle) {
$detalle->setEmpleado(null);
$this->detalles->removeElement($detalle);
}
}
public function getDetalles()
{
return $this->detalles;
}
.....
这是我的课,可以有很多
<?php
namespace NominaEntityEmpleado;
use NominaEntityEmpleadoEmpleado2;
use DoctrineORMMapping as ORM;
use ZendFormAnnotation;
/**
* EmpleadoDetalles
*
* @ORMTable(name="empleadoDetalles2")
* @ORMEntity
* @AnnotationHydrator("ZendStdlibHydratorObjectProperty")
* @AnnotationName("EmpleadoDetallesForm")
*/
class EmpleadoDetalles2
{
/**
* @var integer
*
* @ORMColumn(name="id", type="integer", nullable=false)
* @ORMId
* @ORMGeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORMColumn(name="salario", type="decimal", precision=10, scale=2, nullable=false)
* @AnnotationType("ZendFormElementText")
* @AnnotationRequired({"required":"true"})
* @AnnotationFilter({"name":"StripTags"})
* @AnnotationOptions({"label":"Salario Diario"})
* @AnnotationAttributes({"class":"form-control"})
*/
private $salario = '0.00';
/**
* @var string
*
* @ORMColumn(name="banco", type="string", length=255, nullable=true)
* @AnnotationType("ZendFormElementText")
* @AnnotationRequired({"required":"true"})
* @AnnotationFilter({"name":"StripTags"})
* @AnnotationOptions({"label":"Banco"})
* @AnnotationAttributes({"class":"form-control"})
*/
private $banco;
/**
* @ORMColumn(name="idEmpleado", type="integer", length=11, nullable=false)
* AnnotationType ("ZendFormElementHidden")
*/
private $idEmpleado;
/**
* @ORMManyToOne(targetEntity="NominaEntityEmpleadoEmpleado2", inversedBy="detalles")
* @ORMJoinColumn(name="idEmpleado", referencedColumnName="id")
* AnnotationType ("ZendFormElementHidden")
*/
private $empleado;
/**
* Allow null to remove association
*
* @param Empleado2 $empleado
*/
public function setEmpleado(Empleado2 $empleado = null)
{
$this->empleado = $empleado;
}
/**
* @return Empleado2
*/
public function getEmpleado()
{
return $this->empleado;
}
我有这个在我的看法
echo $this->formRow($form->get('nombre'));
echo $this->formRow($form->get('detalles')->get('salario'));
echo $this->formRow($form->get('detalles')->get('banco'));
我正在正确地从数据库中获取字段,但不是。我在composedObject中一无所获,在我的情况下,它是"detalles",我认为这是因为detalles可以是许多相同类型的对象,但我不确定如何使其在中工作
到目前为止只是部分答案。
输入的语法:
/**
* @ORMOneToMany(targetEntity="NominaEntityEmpleadoEmpleadoDetalles2", mappedBy="empleado")
* @AnnotationComposedObject("NominaEntityEmpleadoEmpleadoDetalles2",is_collection=true,options={"count":1})
*/
需要
/**
* @ORMOneToMany(targetEntity="NominaEntityEmpleadoEmpleadoDetalles2", mappedBy="empleado")
* @AnnotationComposedObject({"target_object":"NominaEntityEmpleadoEmpleadoDetalles2",
* "is_collection":"true",
* "options":{"count":1} })
*/
"@Annotations\ComposedObject"注释可以采用字符串作为目标类名,也可以采用数组,如我上面所示。
我无法使"count":1或任何"count"起作用,但如果您将"label":"something"放在选项子数组中,您可以看到它正在被读取。
现在,一旦我成功地指定我的Composed Object是一个集合,我就开始收到其他错误。。。。