Reputation: 9
I'm currently learning Symfony2 and I'm stuck on the forms. To be more specific, I try to set up a system of comment on an entity announcement.
Unfortunately, when creating the commentaireType.php, using the php app/console doctrine:generate:form OCPlatformBundle:Commentaires I have an error message is this:
[Twig_Error_Runtime] Key "advert" for array with keys "id, auteur, contenu, date, ip" does not exist in "form/FormType.php.twig" at line 29
I noticed that by removing the ManyToOne relation of the entity that I tie, I no longer have the error message.
/**
* @ORM\ManyToOne(targetEntity="OC\PlatformBundle\Entity\Advert", inversedBy="commentaires")
* @ORM\JoinColumn(nullable=false)
*/
private $advert;
Someone would have a solution to my problem? Thank you in advance !
Chiraq.
Upvotes: 0
Views: 3095
Reputation: 12012
The solution for your problem lies in the file FormType.php.twig
under the path:
vendor/sensio/generator-bundle/Resources/skeleton/form/FormType.php.twig
on the line 29:
{%- if fields_mapping[field]['type'] in ['date', 'time', 'datetime'] %}
Change this to:
{%- if fields_mapping[field] is defined and fields_mapping[field]['type'] in ['date', 'time', 'datetime'] %}
and rerun the command. Eventually remove the controller that has been previously created.
Here are another useful links:
Generating forms with Symfony 2.8 throws a Twig_Error_Runtime
https://github.com/sensiolabs/SensioGeneratorBundle/pull/431
https://github.com/sensiolabs/SensioGeneratorBundle/issues/443
Good luck!
Upvotes: 2