我无法访问我的登录页面,我不知道为什么......
security.xml:
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/admin/login$
security: false
secured_area:
pattern: ^/admin
remember_me:
key: "%secret%"
lifetime: 604800 # 7 jours en secondes
path: /login
domain: ~ # Prend la valeur par défaut du domaine courant depuis $_SERVER
form_login:
check_path: _login_check
login_path: _admin_login
default_target_path: /admin
always_use_default_target_path: true
logout:
path: _admin_logout
target: /
#anonymous: ~
#http_basic:
# realm: "Secured Demo Area"
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
- { path: ^/admin, roles: [ROLE_ADMIN] }
- { path: ^/, roles: [ROLE_USER, ROLE_ADMIN] }
routing.yml:
_admin_login:
resource: "@TestBackBundle/Controller/SecureController.php"
type: annotation
secureController.php:
...
/**
* @Route("/admin")
*/
class SecureController extends Controller
{
/**
* @Route("/login", name="_admin_login")
* @Template()
*/
public function loginAction(Request $request)
{
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
} else {
$error = $request->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
}
return array(
'last_username' => $request->getSession()->get(SecurityContext::LAST_USERNAME),
'error' => $error,
);
}
/**
* @Route("/login_check", name="_login_check")
*/
public function securityCheckAction()
{
// The security layer will intercept this request
}
/**
* @Route("/logout", name="_admin_logout")
*/
public function logoutAction()
{
// The security layer will intercept this request
}
}
当我测试访问
时我遇到此错误:找不到“GET / admin”的路由
为什么我的登录页面上的路由不起作用?
答案 0 :(得分:2)
我想这条路线: http://site1.local/app_dev.php/admin/login
当你想要通过它调用它时,你必须将它称为" indexAction" http://site1.local/app_dev.php/admin
说明:
访问此课程的所有路线都经过/ admin
如果你想在/ admin显示内容,你必须创建" indexAction"
然后所有其他操作,例如loginAction具有/ login as route
所以你访问了班级" / admin"并访问loginAction" / login"所以它的/ admin / login /