我使用FSOUserBundle,我想重寫的LoginAction,我用這個方法:fosuserbundle覆蓋登錄操作
namespace PjDZ\UserBundle\Controller;
use FOS\UserBundle\Controller\SecurityController as BaseController;
class SecurityController extends BaseController {
public function loginAction(\Symfony\Component\HttpFoundation\Request $request)
{
/** @var $session \Symfony\Component\HttpFoundation\Session\Session */
$session = $request->getSession();
// get the error if any (works with forward and redirect -- see below)
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
} elseif (null !== $session && $session->has(SecurityContext::AUTHENTICATION_ERROR)) {
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
} else {
$error = '';
}
if ($error) {
// TODO: this is a potential security risk (see http://trac.symfony-project.org/ticket/9523)
$error = $error->getMessage();
}
// last username entered by the user
$lastUsername = (null === $session) ? '' : $session->get(SecurityContext::LAST_USERNAME);
$csrfToken = $this->container->has('form.csrf_provider')
? $this->container->get('form.csrf_provider')->generateCsrfToken('authenticate')
: null;
return $this->renderLogin(array(
'last_username' => $lastUsername,
'error' => $error,
'csrf_token' => $csrfToken,
));
}
}
但是當我嘗試顯示/登錄頁面我得到一個空白頁,什麼想法!? 。 原諒我的壞英語。
完全有效的答案,清除緩存是我忽視做的事情,但爲我解決了這個問題。 – Lewis