我試圖拼命地用實體城市OneToMany Anagrafic保存表單。 我進入了「property_path」 CityType的形式和我返回錯誤,Symfony2預期的參數類型「對象或數組」,「字符串」給出
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];
你有什麼錯誤? – cheesemacfly 2013-02-22 22:14:41
這是一個測驗! 「我得到一個錯誤,並且不會顯示完整的代碼或錯誤點」 – Fusselchen 2013-02-22 22:21:29
它是標題。 '預期的參數類型「對象或數組」,「字符串」給出了' – Lughino 2013-02-22 22:26:49