php - Symfony2 formtype how to pass data -
i build form contains data 2 related entities , able update both entities 1 submit. far, got working form uses formtype static data (e.g. $foo = 'bar'). don't how pass data controller formtype , using in formtype...
this i've got:
// admincontroller.php // throws exception $em = $this->getdoctrine()->getmanager(); $article = $em->getrepository('acmeblogbundle:articles')->find($id); $form = $this->createform(new articlestype(), $article);
this throws exception:
expected argument of type "array or (\traversable , \arrayaccess)", "string" given
so, tried doing this
//this working, (of course) empty $article = new articles(); $form = $this->createform(new articlestype(), $article);
by way articlestype.php
class articlestype extends abstracttype { public function buildform(formbuilderinterface $builder, array $options) { $builder->add('headline', 'text', array('label' => false)) ->add('articlecontent', 'textarea') ->add('state', 'entity', array('class' => 'acme\blogbundle\entity\status', 'property' => 'status', 'label' => false)) ->add('category', 'entity', array('class' => 'acme\blogbundle\entity\categories', 'property' => 'cat_name', 'label' => false)) ->add('save', 'submit') ->add('aufstellung', 'collection', array('type' => new aufstellungtype())); } public function setdefaultoptions(optionsresolverinterface $resolver) { $resolver->setdefaults(array( 'data_class' => 'acme\blogbundle\entity\articles', )); } public function getname() { return 'articles'; } }
edit:
critical - uncaught php exception symfony\component\form\exception\unexpectedtypeexception: "expected argument of type "array or (\traversable , \arrayaccess)", "string" given" @ c:\projects\my_project_name\vendor\symfony\symfony\src\symfony\component\form\extension\core\eventlistener\resizeformlistener.php line 84
Comments
Post a Comment