尝试使用这个页面上的教程。
问题是我总是回到登录表单,找不到我缺少什么。 我正在使用Symfony 3版本。 谢谢你的帮助 :)
问题是我总是回到登录表单,找不到我缺少什么。 我正在使用Symfony 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,
));
}
}