首页 > 解决方案 > Cannot read index "type" from object of type "stdClass" because it doesn't implement \ArrayAccess

问题描述

I am getting this error on this

if ($this->container->getParameter('sso.so') === true) {
    $builder->add('familyMembers', CollectionType::class, array(
        'type' => new FamilyMember(),
        'allow_add' => TRUE,
        'allow_delete' => TRUE,
        'by_reference' => FALSE,
    ));
    $builder->get('familyMembers')->setData(array());
}

this is the form Type

class FamilyMember extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder
            ->add('type', ChoiceType::class, array(
                'label'     => ' ',
                'required'  => FALSE,
                'choices'   => array(
                    'SP'    => 'account.address.option.type.SP',
                    'DP'    => 'account.address.option.type.DP',
                ),
                'expanded'  => TRUE,
                'multiple'  => FALSE,
                'placeholder' => FALSE,
            ))

what I am trying to do is allow the form to be created if they meet that condition.

this worked but i updated to symfony2.8 and I also went from guzzle3 to guzzle 6 (doubt is this one)

标签: phpsymfonytwigsymfony-formsguzzle6

解决方案


根据从 Symfony 2.8 开始的文档, entry_type替换了type

$builder->add('familyMembers', CollectionType::class, array(
        'entry_type' => new FamilyMember(),
        'allow_add' => TRUE,
        'allow_delete' => TRUE,
        'by_reference' => FALSE,
    ));

推荐阅读