我已閱讀關於此錯誤的每個線程,我無法揣摩出這是來自。陣列字符串轉換ArrayChoiceList
我有很多正在從陣列填充複選框字段的形式。然而,在我的實體,我將所有的字段轉換爲一個逗號分隔的字符串(是的,我知道這是醜陋的)和問題的領域都工作正常,但我得到這個錯誤,我根本無法弄清楚問題在哪裏來自。當我調試這些領域它給了我,是正在討論的陣列和我能夠解決這些問題
我也有另外4組的EntityType選擇列表,從4個其他數據庫表填充的。所有的數據和拉正常工作的所有實體,但是當我試圖堅持,我得到這個錯誤的數據庫是,但我找不到什麼實體或陣列/場,這是指任何引用。我在下面看到的是空陣列。
如果看到我的實體和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連接表,risk_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;
ProgramsType表格類 這有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))