Zrobiłem nadpisywanie formularza rejestracyjnego tak jak jest w dokumentacji: https://github.com/FriendsOfSymfony/FOSUser...riding_forms.md
Dodałem kilka pól i wszystko działa teraz chce aby była możliwość edycji danych. Po przeanalizowaniu pakietu stwierdziłem że trzeba nadpisać kontroler ProfilControler, ProfileFormType i ProfileFormHandler, zrobiłem prawie analogiczne do rejestracji, czyli:
w ProfileFormType:
parent::buildForm($builder, $options); $builder->add('imie') ->add('nazwisko','text') ->add('telefon','text') ->add('miejscowosc','text') ->add('dataurodzienia','birthday') 1 => 'Kobieta', 2 => 'Meczyzna' ))) ->add('pesel','text'); } public function getName(){ return 'my_user_profile'; }
ProfileFormHandler
protected function onSuccess(UserInterface $user) { $data_ur=date_format($user->getDataurodzienia(),"Y-m-d"); $user->setWiek($wiek); //$this->userManager->updateUser($user); parent::onSuccess($user); }
w services.xml dodałem:
<service id="my_user.profile.form.type" class="My\FrontendBundle\Form\Type\ProfileFormType"> <tag name="form.type" alias="my_user_profile"/> <argument>%fos_user.model.user.class%</argument> </service> <service id="my_user.profile.form.handler.default" class="My\FrontendBundle\Form\Handler\ProfileFormHandler" scope="request" public="false"> <argument type="service" id="fos_user.profile.form" /> <argument type="service" id="request" /> <argument type="service" id="fos_user.user_manager" /> </service>
oraz w conifig.yml
... profile: form: type: my_user_profile handler: my_user.profile.form.handler.default
Teraz w nadpisałem akcje edit w ProfileController:
/** * Edit the user */ public function editAction() { $user = $this->container->get('security.context')->getToken()->getUser(); throw new AccessDeniedException('This user does not have access to this section.'); } $form = $this->container->get('my_user.profile.form.type'); //$form = $this->container->get('fos_user.profile.form'); <- zmiana $formHandler = $this->container->get('my_user.profile.form.handler.default'); //$formHandler = $this->container->get('fos_user.profile.form.handler'); <- zmiana $process = $formHandler->process($user); if ($process) { $this->setFlash('fos_user_success', 'profile.flash.updated'); return new RedirectResponse($this->getRedirectionUrl($user)); } return $this->container->get('templating')->renderResponse( 'FOSUserBundle:Profile:edit.html.'.$this->container->getParameter('fos_user.template.engine'), ); }
Teraz jak uruchamiam projekt to twierdzi że nie zna 'my_user.profile.form.handler.default' .
Wie ktoś gdzie robię błąd.
Z góry dziękuje za pomoc.