我的symfony2项目中出现此错误:
表单的视图数据应该是类
Sub rename() Dim sName As String sName = Application.InputBox _ (Prompt:="Enter new worksheet name") Range("C4").Validation.Delete On Error Resume Next ActiveWorkbook.SaveAs ActiveWorkbook.Path & "\" & sName & ".xlsm", ConflictResolution:=xlUserResolution On Error GoTo 0 End Sub
的实例,但是是类Proyecto\AdminBundle\Entity\Unidades
的实例。您可以通过设置" data_class"来避免此错误。 null的选项或添加视图转换器,将类Proyecto\AdminBundle\Entity\Catalogo
的实例转换为Proyecto\AdminBundle\Entity\Catalogo
的实例。
避免使用getter,setter和实体属性等几件事。
Catalogo.php
Proyecto\AdminBundle\Entity\Unidades
Unidades.php
class Catalogo
{
/**
* @ORM\OneToMany(targetEntity="Unidades", mappedBy="catalogo")
*/
protected $unidades;
public function __construct()
{
$this->unidades = new ArrayCollection();
}
public function getUnidades()
{
return $this->unidades;
}
public function setUnidades($unidades)
{
$this->unidades[] = $unidades;
foreach ($unidades as $unidad) {
$unidad->setCatalogo($this);
}
}
CatalogoUnidadesType.php
class Unidades
{
/**
* @ORM\ManyToOne(targetEntity="Catalogo", inversedBy="unidades")
* @ORM\JoinColumn(name="catalogo_id", referencedColumnName="id")
*/
protected $catalogo;
/**
* Set catalogo
*
* @param float $catalogo
* @return Unidades
*/
public function setCatalogo($catalogo)
{
$this->catalogo = $catalogo;
return $this;
}
/**
* Get catalogo
*
* @return float
*/
public function getCatalogo()
{
return $this->catalogo;
}
CatalogoType.php
<?php
namespace Proyecto\AdminBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class CatalogoUnidadesType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('catalogo', new CatalogoType());
$builder->add('unidades', new UnidadesType());
}
public function setDefaultOptions(\Symfony\Component\OptionsResolver\OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Proyecto\AdminBundle\Entity\Unidades'
));
}
public function getName()
{
return 'catalogounidades_form';
}
}
UnidadesType.php
<?php
namespace Proyecto\AdminBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class CatalogoType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('articulo');
$builder->add('descripcion');
}
public function setDefaultOptions(\Symfony\Component\OptionsResolver\OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Proyecto\AdminBundle\Entity\Catalogo'
));
}
public function getName()
{
return 'catalogo_form';
}
}
AdminController.php
<?php
namespace Proyecto\AdminBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class UnidadesType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('medida');
$builder->add('precio');
}
public function setDefaultOptions(\Symfony\Component\OptionsResolver\OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Proyecto\AdminBundle\Entity\Unidades'
));
}
public function getName()
{
return 'unidades_form';
}
}
答案 0 :(得分:0)
您应该构建一个名为b
的类,其中包含CatalogoUnidades
和Catalog
,然后为其创建一个FormType。
我希望这会有所帮助。