You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to make the controller a bit more readable and clean up some code rests I found.
Example of the ChangePasswordController, which is in my opinion much more readable than the master:
<?php
/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\UserBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use FOS\UserBundle\Model\UserInterface;
/**
* Controller managing the password change
*
* @author Thibault Duplessis <thibault.duplessis@gmail.com>
* @author Christophe Coevoet <stof@notk.org>
*/
class ChangePasswordController extends Controller
{
public function changePasswordAction()
{
$user = $this->getUser();
if (!is_object($user) || !$user instanceof UserInterface) {
throw new AccessDeniedException('This user does not have access to this section.');
}
$process = $this->getUserFormHandler()->process($user);
if ($process) {
$this->setFlash('fos_user_success', 'change_password.flash.success');
return $this->redirect($this->generateUrl('fos_user_profile_show'));
}
return $this->render('FOSUserBundle:ChangePassword:changePassword.html', array(
'form' => $this->getUserForm()->createView()
));
}
protected function getUserForm()
{
return $this->container->get('fos_user.change_password.form');
}
protected function getUserFormHandler()
{
return $this->container->get('fos_user.change_password.form.handler');
}
protected function setFlash($action, $value)
{
$this->container->get('session')->setFlash($action, $value);
}
}
As you see I have switched from the ContainerAware to the above layer, the controller.
Is there a specific reason why not to use the Controller but the ContainerAware?
The text was updated successfully, but these errors were encountered:
Hello,
I would like to make the controller a bit more readable and clean up some code rests I found.
Example of the ChangePasswordController, which is in my opinion much more readable than the master:
As you see I have switched from the ContainerAware to the above layer, the controller.
Is there a specific reason why not to use the Controller but the ContainerAware?
The text was updated successfully, but these errors were encountered: