2016-04-12 21 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 
相關問題