2
votes

I know that this question have been asked many times but I don't found a solution on the Web who correspond to my problem. So, I've create a UserBundle and when I try to access to the login page, I have the following error:

The autoloader expected class "ET\Bundle\UserBundle\Controller\SecurityController" to be defined in file "C:\xampp\htdocs\lab/src\ET\Bundle\UserBundle\Controller\SecurityController.php". The file was found but the class was not in it, the class name or namespace probably has a typo.

I've check my file if my namespace or my class name are good, but I can't find the mistake.

My 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,
    ));
}
}

My firewall :

    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: / 

My router :

login:
     pattern:   /login
     defaults:  { _controller: ETUserBundle:Security:login }

 login_check:
     pattern:  /login_check

logout:
   pattern:   /logout

If anyone have an idea for me please. Thanks in advance. I've tried this on Symfony 2.6 and 2.7, with a new installation.

1
What is the path of SecurityController.php ?M Khalid Junaid
C:\xampp\htdocs\lab\src\ET\Bundle\UserBundle\Controller\AragornD7
Your namespace should be ET\Bundle\UserBundle\Controller ,Bundle after ETM Khalid Junaid
Ok, it works, thank you :) I just don't understand why they add the Bundle folder but ok ^^AragornD7
You have to follow docs correctly :)M Khalid Junaid

1 Answers

1
votes

replace namespace ET\UserBundle\Controller;by namespace ET\Bundle\UserBundle\Controller\SecurityController