php - Symfony2 FOSUserBundle - additional form -
i want add step register. have own formtype "firma" tries in additional method in registercontroller. when calling action in controller gets error:
fatal error: call undefined method my\frontendbundle\form\type\firmatype::createview() in /var/www/budowlanka/src/my/frontendbundle/controller/registrationcontroller.php on line 107
nextstepaction action in registercontroller
public function nextstepaction($token) { $user = $this->container->get('fos_user.user_manager')->finduserbyconfirmationtoken($token); if (null === $user) { throw new notfoundhttpexception(sprintf('the user confirmation token "%s" not exist', $token)); } $this->container->get('fos_user.user_manager')->updateuser($user); $form = $this->container->get('my_user.firma.form.type'); . . . return $this->container->get('templating')->renderresponse('fosuserbundle:registration:register.html.' . $this->getengine(), array( 'form' => $form->createview(), 'theme' => $this->container->getparameter('fos_user.template.theme'), ));
service.xml:
<service id="my_user.firma.form.type" class="my\frontendbundle\form\type\firmatype"> <tag name="form.type" alias="my_user_firma" /> <argument>my\frontendbundle\entity\firma</argument> </service>
firmatype:
namespace my\frontendbundle\form\type; use symfony\component\form\abstracttype; use symfony\component\form\formbuilder; class firmatype extends abstracttype { public function buildform(formbuilder $builder, array $options) { $builder ->add('nazwa') ->add('ulica') ->add('nr_budynku') ->add('nr_lokalu') ->add('miasto') ->add('kod_pocztowy') ->add('poczta') ->add('telefon_1') ->add('telefon_2') ->add('email') ->add('www') ->add('liczba_opinii') ->add('nip') ->add('imie') ->add('nazwisko') ->add('haslo') ->add('logo') ->add('opis_uslug') ->add('data_dodania') ->add('data_modyfikacji') ->add('slug') ->add('specjalizacje') ; } public function getname() { return 'my_frontendbundle_firmatype'; } }
edit:
it works great have problem labels manytomany relationship field.
->add('specjalizacja', 'entity', array( 'label' => 'specjalizacje', 'multiple' => true, 'expanded' => true, 'property' => 'nazwa', 'class' => 'my\frontendbundle\entity\specjalizacja', 'query_builder' => function(\doctrine\orm\entityrepository $er) { $qb = $er->createquerybuilder('g'); return $qb->orderby('g.nazwa', 'desc'); } )
it displays 'my_user_firma_form_specjalizacja_110' label (110 id of record) instead nazwa field of entity. have __tostring() method in specjalizacja entity class
you should use formfactory create form.
<service id="my_user.firma.form" factory-method="createnamed" factory-service="form.factory" class="symfony\component\form\form"> <argument>my_user_firma</argument> <argument>'my_user_firma_form'</argument> </service> <service id="my_user.firma.form.type" class="my\frontendbundle\form\type\firmatype"> <tag name="form.type" alias="my_user_firma" /> <argument>my\frontendbundle\entity\firma</argument> </service>
and call..
$form = $this->container->get('my_user.firma.form');
from here should able use $form->createview()
.
Comments
Post a Comment