login - Symfony2 : login_check and annotation -
in symfony project, utilize authentification. wrote in security.yml file
firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false default: anonymous: ~ login_firewall: pattern: ^/login$ anonymous: ~ secured_area: pattern: ^/ anonymous: ~ form_login: login_path: /login check_path: /login_check post_only: true always_use_default_target_path: true default_target_path: / use_referer: false username_parameter: username password_parameter: password intention: authenticate logout: path: /logout target: /ok, documentation says need add together in routing.yml :
login: pattern: /login defaults: { _controller: acmesecuritybundle:security:login } login_check: pattern: /login_checkbut using annotation, don't utilize routing files. instead have :
/** * @route("/login") * @template() */ public function loginaction() { $request = $this->getrequest(); $session = $request->getsession(); // login error if there 1 if ($request->attributes->has(securitycontext::authentication_error)) { $error = $request->attributes->get(securitycontext::authentication_error); } else { $error = $session->get(securitycontext::authentication_error); $session->remove(securitycontext::authentication_error); } homecoming array( // lastly username entered user 'last_username' => $session->get(securitycontext::last_username), 'error' => $error, ); }if nothing, have error in login page :
"unable generate url named route "login_check" such route not exist."if add together action in controller empty response, there is... nothing.
what doing wrong ?
login_check
or whatever specify scheme defined route , not action. means can not/shall not/will not define manually in controller. ;)
i myself utilize annotations
routing but, 1 way or another, utilize routing.yml
in order import controllers , annotated routes within them.
so, go ahead, define route in routing.yml
, should work.
symfony2 login annotations
No comments:
Post a Comment