Hi,

here is a controller action from the DoctrineUserBundle:
    public function createAction()
    {
        $form = $this->createForm();
        $form->bind($this['request']->request->get($form->getName()));

        if ($form->isValid()) {
            $user = $form->getData();
            if 
($this->container->getParameter('doctrine_user.confirmation_email.enabled')) {
                $user->setIsActive(false);
                $this->saveUser($user);
                
$this['session']->set('doctrine_user_send_confirmation_email/email', 
$user->getEmail());
                $url = 
$this->generateUrl('doctrine_user_user_send_confirmation_email');
            } else {
                $user->setIsActive(true);
                $this->saveUser($user);
                $this['doctrine_user.auth']->login($user);
                $url = $this->generateUrl('doctrine_user_user_confirmed');
            }

            $this['session']->setFlash('doctrine_user_user_create/success', 
true);
            return $this->redirect($url);
        }

        return 
$this->render('DoctrineUserBundle:User:new.'.$this->getRenderer(), array(
            'form' => $form
        ));
    }

Now this is is good if the form was submitted directly. But this action is 
unusable if the method is called via AJAX. In order to make the form work via 
AJAX I created a little wrapper controller that can then load the 
DoctrineUserBundle and return the html. This is already not so nice, but works.

As you can see it does a redirect() in case the form is valid and this of 
course doesnt work nor does it make sense for an AJAX request. In an AJAX 
request it should probably return the content for the route its redirecting to. 
Now obviously I can add some code to handle this case, but I wonder if there 
isnt a more generic approach we could implement and make available inside the 
Controller class to ensure that its brain dead simple for Bundle authors to 
provide controllers that can be used via direct requests as well as AJAX.

For now I will change the DoctrineUserBundle to use service definitions for the 
controllers, so that we can easily replace the controller with our own 
implementation. But right now I must say I am very concerned that we still have 
a lot of work in order to make 3rd party Bundles truly viable. Right now one 
could just as well publish a gist because the code tends to need so much hands 
on customization.

regards,
Lukas Kahwe Smith
[email protected]



-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to