現在、FOSUSerBundle、SonataAdminBundle、および SonataUserBundle を使用して、Symfony 2.5.0 でアプリを開発しています。私は FOSUserbundle を拡張したので、私の AppKernel.php はnew Sonata\UserBundle\SonataUserBundle('FOSUserBundle')
、Easy Extends を使用して独自の Application\Sonata\UserBundle を生成しました。
私の Application\SonataUserBundle では、次のように ChangePasswordFOSUser1Controller をオーバーライドしました。
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\HttpFoundation\Request;
use FOS\UserBundle\Model\UserInterface;
use Sonata\UserBundle\Controller\ChangePasswordFOSUser1Controller as BaseController;
class ChangePasswordFOSUser1Controller extends BaseController
{
public function changePasswordAction()
{
$user = $this->container->get('security.context')->getToken()->getUser();
if (!is_object($user) || !$user instanceof UserInterface)
{
throw new AccessDeniedException('This user does not have access to this section.');
}
$form = $this->container->get('fos_user.change_password.form');
$formHandler = $this->container->get('fos_user.change_password.form.handler');
$process = $formHandler->process($user);
if ($process)
{
$this->setFlash('fos_user_success', 'change_password.flash.success');
if ($user->getFirstConnection())
$user->setFirstConnection(false);
return new RedirectResponse($this->getRedirectionUrl($user));
}
return $this->container->get('templating')->renderResponse('SonataUserBundle:ChangePassword:changePassword.html.'.$this->container->getParameter('fos_user.template.engine'),
array('form' => $form->createView()));
}
/**
* {@inheritdoc}
*/
protected function getRedirectionUrl(UserInterface $user)
{
return $this->container->get('router')->generate('front_home');
}
/**
* @param string $action
* @param string $value
*/
protected function setFlash($action, $value)
{
$this->container->get('session')->getFlashBag()->set($action, $value);
}
}
問題は次のとおりです。ログイン ページにアクセスすると、ログイン フォームの直前の「ヘッダー セクション」にコントローラのコードが 2 回表示されます。
キャッシュとVOILAをクリアしようとしました! キャッシュはクリアされますが、シェルで同じコードが 2 回出力されます。(ええ、私はシェルで作業します)
キャッシュをクリアすると「バグ」が何度も発生しますが、ログインページでは、2 ページを更新すると消えます。
誰かがそのコントローラーをオーバーライドしようとしたり、同様のエラーが発生したりしましたか? (誰も持っていなかったのは残念だろう)
助けてくれてありがとう!