2017-05-03 19 views
1

Symfony2でルーティングに関する問題が発生しています。symfony2の注釈ルーティングが原因でcache:clearが失敗する

私は現在、@Route注釈を使用しようとしています。デバッグを有効にしたdev環境では、すべて動作します。デバッグを有効にしたprodでは、すべて動作します。デバッグを無効にすると、インデックスルートだけが応答し、それ以外はすべて404を返します。

私は当初はキャッシュだと思っていました。それは私の次の問題につながった:

[Doctrine\Common\Annotations\AnnotationException] 
    [Semantical Error] The annotation "@Sensio\Bundle\FrameworkExtraBundle\Configuration\Route" in method LeagueOfData\Controller\DefaultController::indexAction() does not exist, or could not be auto-loaded. 

あなたがbin/console cache:clear --env=prodまたはbin/console cache:clear --env=devを実行すると、このエラーが表示されます。

私はすべてが正しく設定されていることを確認しました(念頭に置いて、これはブラウザで完全に正常に動作し、環境に関係なくデバッグが有効になります)。

のrouting.yml

parser: 
    resource: "@LeagueOfData/Controller/" 
    type:  annotation 

これは(DEVによりオーバーライドする)config.ymlrouting_dev.ymlに含まれています。

AppKernal.php

public function registerBundles() 
{ 
    $bundles = [ 
     new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), 
     new Symfony\Bundle\MonologBundle\MonologBundle(), 
     new Symfony\Bundle\TwigBundle\TwigBundle(), 
     new Symfony\Bundle\SecurityBundle\SecurityBundle(), 
     new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), 
     new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), 
     new LeagueOfData\LeagueOfData() 
    ]; 

    if (in_array($this->getEnvironment(), ['dev', 'test'], true)) { 
     $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle(); 
     $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); 
    } 

    return $bundles; 
} 

SensioFrameworkExtraBundleが正しく登録されています。 (完全なソース:https://github.com/Acaeris/lol-parser/blob/broken-routing/app/AppKernel.php

app.php

<?php 

use Symfony\Component\HttpFoundation\Request; 
use Symfony\Component\Debug\Debug; 

/** @var \Composer\Autoload\ClassLoader $loader */ 
$loader = require __DIR__.'/../app/autoload.php'; 
Debug::enable(); 

$kernel = new AppKernel('dev', true); 
$kernel->loadClassCache(); 
$request = Request::createFromGlobals(); 
$response = $kernel->handle($request); 
$response->send(); 
$kernel->terminate($request, $response); 

あなたが見ることができるように

<?php 

use Symfony\Component\HttpFoundation\Request; 

/** @var \Composer\Autoload\ClassLoader $loader */ 
$loader = require __DIR__ . '/../app/autoload.php'; 
include_once __DIR__ . '/../app/bootstrap.php.cache'; 

$kernel = new AppKernel('prod', false); 
$kernel->loadClassCache(); 

$request = Request::createFromGlobals(); 
$response = $kernel->handle($request); 
$response->send(); 
$kernel->terminate($request, $response); 

app_dev.php、あまりの違い。キーはデバッグを可能にするようですが、なぜですか?例として、あなたがuse声明でそれをインポートする必要がhttps://github.com/Acaeris/lol-parser/tree/broken-routing

答えて

0

:それは誰もお手伝いします場合

完全なソースはGitHubの上にある

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; 

・ホープ、このヘルプ

+0

'@Route 'はすでにコントローラに一致するuse文を持っています。そうでなければ、デバッグを有効にしても動作しません。 – Acaeris

+0

これはどのように使用しますか:Symfony \ Component \ Routing \ Annotation \ Route? – jeremy

関連する問題