2016-06-13 12 views
0

Ich habe jeden Thread in Bezug auf diesen Fehler gelesen und ich kann nicht herausfinden, woher das kommt.Array zu String-Konvertierung ArrayChoiceList

Ich habe ein Formular mit vielen Kontrollkästchen Felder, die von Arrays gefüllt werden. In meiner Entity konvertiere ich jedoch alle Felder in eine durch Komma getrennte Zeichenfolge (ja, ich weiß, das ist hässlich) und die fraglichen Felder funktionieren alle gut, aber ich bekomme diesen Fehler und ich kann einfach nicht herausfinden, wo das Problem liegt kommt aus. Als ich diese Felder debugging gab es mir die Arrays, die in Frage waren und ich konnte sie beheben

Ich habe auch noch 4 weitere EntityType Auswahllisten, die aus 4 anderen Datenbanktabellen auffüllen. Alle Daten ziehen und funktionieren ordnungsgemäß für alle Entitäten, aber wenn ich versuche, die Datenbank persistent zu machen, bekomme ich diesen Fehler, aber ich kann keinen Verweis darauf finden, auf welche Entity oder Array/Feld sich dies bezieht. Alles was ich unten sehe sind leere Arrays.

Wenn ich meine Entity und FormType sehe, kann ich diese veröffentlichen.

[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 Datenbankstruktur hat 5 Haupttabellen und Verbindungstabellen für jeden ManyToMany

programs (main table) 
- id 
- other columns 

keywords 
- id 
- other columns 

programs_keywords 
- program_id 
- keyword_id 

und so weiter für Tabellen Kategorien, protective_factors, risk_factors

Programme Entity

/** 
* @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 Formularklasse Dies hat m y-Entitäten hinzugefügt, aber auch wie erwähnt eine Tonne anderer ChoiceType-Felder, die aus Arrays gefüllt sind, aber diese scheinen alle gut zu funktionieren.

 ->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)) 

Antwort

1

Schließlich löste dies. Das Problem war, dass ich ChoiceType-Felder, die nicht auf multiple = true festgelegt waren, in ein Array und zurück in meine Entity umwandelte.

Einfacher Fehler aber übersehen es so oft.