我从 Symfony 3 和 EasyAdminBundle 开始。我的问题是当我尝试使用外键编辑或创建实体时出现异常:
“可捕获的致命错误:Proxies__CG__\AppBundle\Entity\Modelo 类的对象无法转换为字符串 500 内部服务器错误 - ContextErrorException”在 vendor\symfony\symfony\src\Symfony\Bridge\Doctrine\Form\Type\DoctrineType.php在第 59 行
public static function createChoiceLabel($choice)
{
return (string) $choice;
}
车辆类型.php
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class VehiculoType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('patente')->add('modelo', 'entity');
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\Vehiculo'
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'appbundle_vehiculo';
}
public function __toString()
{
return (string) $this->getVehiculo();
}
}
还有我的实体 Vehicolo.php
namespace AppBundle\Entity;
/*** Vehiculo*/
class Vehiculo{
/**
* @var int
*/
private $id;
/**
* @var string
*/
private $patente;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set patente
*
* @param string $patente
*
* @return Vehiculo
*/
public function setPatente($patente)
{
$this->patente = $patente;
return $this;
}
/**
* Get patente
*
* @return string
*/
public function getPatente()
{
return $this->patente;
}
/**
* @var string
*/
private $oneToOne;
/**
* Set oneToOne
*
* @param string $oneToOne
*
* @return Vehiculo
*/
public function setOneToOne($oneToOne)
{
$this->oneToOne = $oneToOne;
return $this;
}
/**
* Get oneToOne
*
* @return string
*/
public function getOneToOne()
{
return $this->oneToOne;
}
/**
* @var \AppBundle\Entity\Modelo
*/
private $modelo;
/**
* Set modelo
*
* @param \AppBundle\Entity\Modelo $modelo
*
* @return Vehiculo
*/
public function setModelo(\AppBundle\Entity\Modelo $modelo = null)
{
$this->modelo = $modelo;
return $this;
}
/**
* Get modelo
*
* @return \AppBundle\Entity\Modelo
*/
public function getModelo()
{
return $this->modelo;
}
}