2016-01-31 26 views
1

我在symfony的新的和我以下登錄表單教程https://symfony.com/doc/2.8/cookbook/security/form_login_setup.html),但我得到以下錯誤:Symfony2的SecurityController錯誤

Uncaught PHP Exception LogicException: "The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller?" at /var/www/html/app/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 157 
Context: { "exception": "Object(LogicException)" } 

我用同樣的SecurityController:

class SecurityController extends Controller{ 


* @Route("/admin", name="login") 

public function loginAction(Request $request) 
{ 

$authenticationUtils = $this->get('security.authentication_utils'); 

// get the login error if there is one 
$error = $authenticationUtils->getLastAuthenticationError(); 

// last username entered by the user 
$lastUsername = $authenticationUtils->getLastUsername(); 

return $this->render(
    'security/login.html.twig', 
    array(
     // last username entered by the user 
     'last_username' => $lastUsername, 
     'error'   => $error, 
    ) 
); 
} 

/** 
* @Route("/login_check", name="login_check") 
*/ 
public function loginCheckAction() 
{ 
    // this controller will not be executed, 
    // as the route is handled by the Security system 
} 

security.yml

# To get started with security, check out the documentation: 

http://symfony.com/doc/current/book/security.html

安全:

# http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers 
providers: 
    app_users: 
     ldap: 
      service: app.ldap 
      base_dn: DC=corp, DC=int 
      search_dn: null 
      search_password: null 
      filter: (uid={username}) 
      default_roles: ROLE_USER 

firewalls: 
    # disables authentication for assets and the profiler, adapt it according to your needs 
    dev: 
     pattern: ^/(_(profiler|wdt)|css|images|js)/ 
     security: false 

    main: 
     anonymous: ~ 
     # activate different ways to authenticate 

     # http_basic: ~ 
     # http://symfony.com/doc/current/book/security.html#a-configuring-how-your-users-will-authenticate 

     # form_login: ~ 
     # http://symfony.com/doc/current/cookbook/security/form_login_setup.html 
    secure: 
     provider: app_users 
     form_login_ldap: 
      service: app.ldap 
      dn_string: "uid={username},ou=Users,dc=corp,dc=int" 
      check_path: login_check 
      login_path: admin 
     logout: true 
+0

你的安全配置是什麼樣的? ('應用/配置/ security.yml'的) –

回答

0

在你security.yml,嘗試通過

check_path: /login_check 

更換

check_path: login_check 

而且使ÿ我們的方法是這樣的:

/** 
* @Route("/login_check", name="login_check") 
*/ 
public function loginCheckAction() 
{ 
    throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.'); 
}