我正在拼命地使用实体 City OneToMany Anagrafic 保存表单。我在表单中输入了“property_path”CityType 并返回错误,
Expected argument of type “object or array”, “string” given
我不明白我做错了什么!
class Anagrafic
{
/**
* @ORM\ManyToOne(targetEntity="City", inversedBy="anagrafics", cascade={"persist"})
* @ORM\JoinColumn(name="city_id", referencedColumnName="id")
*/
private $city;
//..
//..
class City
{
/**
* @ORM\OneToMany(targetEntity="Anagrafic", mappedBy="city", cascade={"persist"})
*/
private $anagrafics;
//...
//...
class CityType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('comune', 'hidden', array('property_path' => 'city.id'))
//..
//..
class AnagraficType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('city', new CityType())
编辑:抱歉信息不完整,这是个例外:
CRITICAL - Symfony\Component\Form\Exception\UnexpectedTypeException:
Expected argument of type "object or array", "string" given (uncaught exception) at
/var/www/MyBusiness0_1/vendor/symfony/symfony/src/Symfony/Component/Form/Util/PropertyPath.php line 342
/var/www/MyBusiness0_1/vendor/symfony/symfony/src/Symfony/Component/Form/Util/PropertyPath.php at line 342
for ($i = 0; $i <= $lastIndex; ++$i) {
if (!is_object($objectOrArray) && !is_array($objectOrArray)) {
throw new UnexpectedTypeException($objectOrArray, 'object or array');
}
$property = $this->elements[$i];