2016-06-13 15 views
0

このエラーに関するすべてのスレッドを読みましたが、どこから来ているのかわかりません。配列から文字列への変換ArrayChoiceList

私は配列から取り込まれる多くのチェックボックスフィールドを持つフォームを持っています。しかし、私のエンティティでは、すべてのフィールドをカンマで区切った文字列に変換しています(これは醜いことが分かります)。問題のフィールドはすべて問題なく動作しますが、このエラーが発生しています。から来ている。これらのフィールドをデバッグしているときに問題の配列が見つかりましたが、修正することができました

4つのデータベーステーブルから別の4つのEntityType選択リストを取得しました。すべてのデータが取得され、すべてのエンティティで正常に動作しますが、このエラーが発生したデータベースを永続化しようとしていますが、これが参照しているエンティティまたは配列/フィールドの参照は見つかりません。私が以下で見るのは、空の配列だけです。

私のエンティティとFormTypeを見れば、それらを投稿できます。

[1] Symfony\Component\Debug\Exception\ContextErrorException: Notice: Array to string conversion 
at n/a 
    in /Applications/MAMP/htdocs/mpdb/vendor/symfony/symfony/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php line 73 

at Symfony\Component\Debug\ErrorHandler->handleError('8', 'Array to string conversion', '/Applications/MAMP/htdocs/mpdb/vendor/symfony/symfony/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php', '73', array('choice' => array(''))) 
    in /Applications/MAMP/htdocs/mpdb/vendor/symfony/symfony/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php line 73 

at Symfony\Component\Form\ChoiceList\ArrayChoiceList->Symfony\Component\Form\ChoiceList\{closure}(array('')) 
    in line 

at call_user_func(object(Closure), array('')) 
    in /Applications/MAMP/htdocs/mpdb/vendor/symfony/symfony/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php line 158 

at Symfony\Component\Form\ChoiceList\ArrayChoiceList->getValuesForChoices(array(array(''))) 
    in /Applications/MAMP/htdocs/mpdb/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoiceToValueTransformer.php line 37 

at Symfony\Component\Form\Extension\Core\DataTransformer\ChoiceToValueTransformer->transform(array('')) 
    in /Applications/MAMP/htdocs/mpdb/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 1092 

at Symfony\Component\Form\Form->normToView(array('')) 
    in /Applications/MAMP/htdocs/mpdb/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 352 

at Symfony\Component\Form\Form->setData(array('')) 
    in /Applications/MAMP/htdocs/mpdb/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php line 57 

at Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper->mapDataToForms(object(Programs), object(RecursiveIteratorIterator)) 
    in /Applications/MAMP/htdocs/mpdb/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 385 

at Symfony\Component\Form\Form->setData(object(Programs)) 
    in /Applications/MAMP/htdocs/mpdb/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 477 

at Symfony\Component\Form\Form->initialize() 
    in /Applications/MAMP/htdocs/mpdb/vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php line 226 

at Symfony\Component\Form\FormBuilder->getForm() 
    in /Applications/MAMP/htdocs/mpdb/vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php line 39 

at Symfony\Component\Form\FormFactory->create('AppBundle\Form\ProgramsType', object(Programs), array()) 
    in /Applications/MAMP/htdocs/mpdb/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php line 309 

at Symfony\Bundle\FrameworkBundle\Controller\Controller->createForm('AppBundle\Form\ProgramsType', object(Programs)) 
    in /Applications/MAMP/htdocs/mpdb/src/AppBundle/Controller/DefaultController.php line 37 

at AppBundle\Controller\DefaultController->nominateAction(object(Request)) 
    in line 

at call_user_func_array(array(object(DefaultController), 'nominateAction'), array(object(Request))) 
    in /Applications/MAMP/htdocs/mpdb/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 148 

at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1') 
    in /Applications/MAMP/htdocs/mpdb/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 66 

at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true) 
    in /Applications/MAMP/htdocs/mpdb/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php line 169 

at Symfony\Component\HttpKernel\Kernel->handle(object(Request)) 

INFO - Matched route "{route}". 
INFO - Populated the TokenStorage with an anonymous Token. 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - SELECT k0_.title AS title_0, k0_.slug AS slug_1, k0_.id AS id_2 FROM keywords k0_ 
DEBUG - SELECT c0_.title AS title_0, c0_.slug AS slug_1, c0_.is_effstrat AS is_effstrat_2, c0_.id AS id_3 FROM categories c0_ WHERE c0_.is_effstrat = 'YES' 
DEBUG - SELECT r0_.title AS title_0, r0_.category AS category_1, r0_.report_text AS report_text_2, r0_.id AS id_3 FROM risk_factors r0_ 
DEBUG - SELECT p0_.title AS title_0, p0_.category AS category_1, p0_.report_text AS report_text_2, p0_.id AS id_3 FROM protective_factors p0_ 
CRITICAL - Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException: "Notice: Array to string conversion" at /Applications/MAMP/htdocs/mpdb/vendor/symfony/symfony/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php line 73 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 
DEBUG - Notified event "{event}" to listener "{listener}". 

MYデータベース構造は、5つの主要テーブルを有し、各多対多テーブルカテゴリの

programs (main table) 
- id 
- other columns 

keywords 
- id 
- other columns 

programs_keywords 
- program_id 
- keyword_id 

などのテーブルを結合する、protective_factors、

プログラムエンティティ

/** 
* @var \Doctrine\Common\Collections\Collection 
* 
* @ORM\ManyToMany(targetEntity="Categories", inversedBy="program") 
* @ORM\JoinTable(name="programs_categories", 
* joinColumns={ 
*  @ORM\JoinColumn(name="program_id", referencedColumnName="id") 
* }, 
* inverseJoinColumns={ 
*  @ORM\JoinColumn(name="category_id", referencedColumnName="id") 
* } 
*) 
* @Assert\Count(min = 1, minMessage = "You must select at least one option.") 
*/ 
private $category; 

/** 
* @var \Doctrine\Common\Collections\Collection 
* 
* @ORM\ManyToMany(targetEntity="Keywords", inversedBy="program") 
* @ORM\JoinTable(name="programs_keywords", 
* joinColumns={ 
*  @ORM\JoinColumn(name="program_id", referencedColumnName="id") 
* }, 
* inverseJoinColumns={ 
*  @ORM\JoinColumn(name="keyword_id", referencedColumnName="id") 
* } 
*) 
* @Assert\Count(min = 1, minMessage = "You must select at least one option.") 
*/ 
private $keyword; 

/** 
* @var \Doctrine\Common\Collections\Collection 
* 
* @ORM\ManyToMany(targetEntity="ProtectiveFactors", inversedBy="program") 
* @ORM\JoinTable(name="programs_protective_factors", 
* joinColumns={ 
*  @ORM\JoinColumn(name="program_id", referencedColumnName="id") 
* }, 
* inverseJoinColumns={ 
*  @ORM\JoinColumn(name="protective_factor_id", referencedColumnName="id") 
* } 
*) 
* @Assert\Count(min = 1, minMessage = "You must select at least one option.") 
*/ 
private $protectiveFactor; 

/** 
* @var \Doctrine\Common\Collections\Collection 
* 
* @ORM\ManyToMany(targetEntity="RiskFactors", inversedBy="program") 
* @ORM\JoinTable(name="programs_risk_factors", 
* joinColumns={ 
*  @ORM\JoinColumn(name="program_id", referencedColumnName="id") 
* }, 
* inverseJoinColumns={ 
*  @ORM\JoinColumn(name="risk_factor_id", referencedColumnName="id") 
* } 
*) 
* @Assert\Count(min = 1, minMessage = "You must select at least one option.") 
*/ 
private $riskFactor; 

をrisk_factorsプログラムタイプフォームクラス これはm yのエンティティが追加されているだけでなく、前述のように、配列からデータが取り込まれる他のChoiceTypeフィールドもたくさんありますが、これらはすべて正常に動作しているようです。

 ->add('keyword', EntityType::class, array('class' => 'AppBundle:Keywords', 'choice_label' => 'title', 'multiple' => true, 'expanded' => true)) 
     ->add('riskFactor', EntityType::class, array('class' => 'AppBundle:RiskFactors', 'choice_label' => 'title', 'multiple' => true, 'expanded' => true)) 
     ->add('protectiveFactor', EntityType::class, array('class' => 'AppBundle:ProtectiveFactors', 'choice_label' => 'title', 'multiple' => true, 'expanded' => true)) 
     ->add('category', EntityType::class, array('class' => 'AppBundle:Categories', 'query_builder' => function (EntityRepository $er) { 
      $qb = $er->createQueryBuilder('c'); 
      $qb->where($qb->expr()->eq('c.isEffstrat', $qb->expr()->literal('YES'))); 
      return $qb; 
     },'choice_label' => 'title', 'multiple' => true, 'expanded' => true)) 

答えて

1

最後にこれを解決しました。問題は、multiple = trueに設定されていないChoiceTypeフィールドを配列に変換して、エンティティに戻すことでした。

簡単な間違いが何度も見落とされました。

関連する問題