我在Symfony2中遇到了很多问题,而我在我的智慧结束时正在寻找答案。
我目前正在尝试使用@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
这包含在config.yml
和routing_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;
/** @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
<?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);
正如你所看到的,差别不大。关键似乎是启用调试......但为什么呢?
完全来源是GitHub,如果它可以帮助任何人:https://github.com/Acaeris/lol-parser/tree/broken-routing
答案 0 :(得分:0)
您需要使用use
语句导入它,例如:
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
希望这个帮助