我知道这个问题已经被问了很多次,但我在网上没有找到与我的问题相对应的解决方案。因此,我创建了一个UserBundle,当我尝试访问登录页面时,出现以下错误:
自动加载器期望在文件"C:''xampp''htdocs''lab/src''ET''Bundle''UserBundle''Controller''SecurityController.php"中定义类"ET''Bundle''UserBundle''UserBundle''Controller''SecurityController"。找到文件,但类不在其中,类名或命名空间可能有拼写错误。
我已经检查了我的文件,我的命名空间或类名是否良好,但我找不到错误。
我的安全控制器 :
<?php
namespace ET'UserBundle'Controller;
use Symfony'Bundle'FrameworkBundle'Controller'Controller;
use Symfony'Component'HttpFoundation'Request;
use Symfony'Component'Security'Core'SecurityContext;
class SecurityController extends Controller{
public function loginAction(Request $request){
// Si le visiteur est déjà identifié, on le redirige vers l'accueil
if ($this->get('security.context')->isGranted(IS_AUTHENTIFICATED_REMEMBERED)){
return $this->redirect($this->generateUrl('et_home'));
}
$session = $request->getSession();
// On vérifie qu'il n'y a pas d'erreurs lors d'un précédente soumission de formulaire
if($request->attributes->has(SecurityContext::AUTHENTIFICATION_ERROR)){
$error = $request->attributes->get(SecurityContext::AUTHENTIFICATION_ERROR);
}else{
$error = $session->get(SecurityContext::AUTHENTIFICATION_ERROR);
$session->remove(SecurityContext::AUTHENTIFICATION_ERROR);
}
return $this->render('ETUserBundle:Security:login.html.twig', array(
'last_username' => $session->get(SecurityContext::LAST_USERNAME),
'error' => $error,
));
}
}
我的防火墙 :
firewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
# the login page has to be accessible for everybody
main:
pattern: ^/
anonymous: true
provider: in_memory
form_login:
login_path: login
check_path: login_check
logout:
path: logout
target: /
我的路由器 :
login:
pattern: /login
defaults: { _controller: ETUserBundle:Security:login }
login_check:
pattern: /login_check
logout:
pattern: /logout
如果有人对我有想法,请。提前谢谢。我已经在Symfony 2.6和2.7上尝试过这个,并安装了新装置。
将
namespace ET'UserBundle'Controller;
替换为namespace ET'Bundle'UserBundle'Controller'SecurityController