尝试在
this页面上使用该教程
问题是我总是回到登录表单,并且无法找到我所缺少的内容.
我正在使用Synfony 3版本.
谢谢你的帮助:)
security: encoders: Symfony\Component\Security\Core\User\User: plaintext providers: in_memory: memory: users: ryan: password: ryanpass roles: 'ROLE_USER' admin: password: admin roles: 'ROLE_USER' firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false home: pattern: ^/home$ form_login: login_path: login check_path: login always_use_default_target_path: true main: anonymous: ~ =========== routing login: path: /login defaults: { _controller: AppBundle:Security:login } btw_user: resource: "@BTWUserBundle/Resources/config/routing.yml" prefix: / btw_menus: resource: "@BTWMenusBundle/Resources/config/routing.yml" prefix: / app: resource: "@AppBundle/Controller/" type: annotation btw_home: resource: "@BTWHomeBundle/Resources/config/routing.yml" prefix: / ============ controller namespace AppBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; class SecurityController extends Controller { public function loginAction(Request $request) { //var_dump($request); $authenticationUtils = $this->get("security.authentication_utils"); //var_dump($_POST); // get the login error if there is one $error = $authenticationUtils->getLastAuthenticationError (); var_dump($error); // last username entered by the user $lastUsername = $authenticationUtils->getLastUsername(); var_dump($lastUsername); return $this->render ( 'security/login.html.twig',array( // last username entered by the user 'last_username' => $lastUsername,'error' => $error,)); } }
解决方法
我也有同样的问题,这解决了我的问题:
context:session_key Read more
并在admin_login yaml块中创建其他form_login.
这不是解决此问题的最佳方法,我会为避免这种情况进行测试,但它确实有效!
用法:
admin_login: pattern: ^/admin/login$ anonymous: ~ provider: user_provider context: session_key form_login: login_path: admin_login check_path: admin_login default_target_path: admin_category_index admin: pattern: ^/admin provider: user_provider context: session_key form_login: login_path: admin_login check_path: admin_login default_target_path: admin_category_index logout: path: /logout target: / invalidate_session: false