2016-04-12 24 views
0

我在启动服务器并尝试访问http://127.0.0.1:8000时收到错误Unable to generate a URL for the named route "login" as such route does not exist.无法为指定的路由“登录”生成URL

到/登录直接访问,得到:No route found for "GET /login"

这是symfony3和无FOSBUNDLE! 基于symfony3 cookbook traditional log form

security.yml:

securityController.php:

// src/AppBundle/Controller/SecurityContoller.php 
namespace AppBundle\Controller; 

use Symfony\Bundle\FrameworkBundle\Controller\Controller; 
use Symfony\Component\HttpFoundation\Request; 
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 

class SecurityController extends Controller 
{ 
/** 
* @Route("/login", name="login") 
*/ 
public function loginAction(Request $request) 
{ 
    $authenticationUtils = $this->get('security.authentication_utils'); 

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

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

return $this->render(
    'security/login.html.twig', 
    array(
    'last_username' => $lastUsername, 
    'error'   => $error, 
) 
); 
} 
} 
+0

请问你的routing.yml文件是什么样子? – Laoneo

+0

它的默认值是否需要手动添加到routing.yml中,即使使用注释? – Diamonte

+0

是的,你需要添加一个路由文件。我发布了一个答案,需要什么。 – Laoneo

回答

2

我猜你缺少的routing.yml文件。在config.yml文件,你需要定义路由部分:

framework: 
    router: 
     resource: "%kernel.root_dir%/config/internal/routing.yml" 
     strict_requirements: ~ 

修改routing.yml文件需要看起来像那么

php: 
    resource: "@AppBundle/Controller/" 
    type:  annotation 
相关问题