繁体   English   中英

Symfony2注释路由导致缓存:清除失败

[英]Symfony2 annotation routing causes cache:clear to fail

我在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=prodbin/console cache:clear --env=dev

所以我检查了所有设置是否正确(记住,在浏览器中完全正常,无论环境如何都启用了调试)。

使用routing.yml

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

这包含在config.ymlrouting_dev.yml (由于dev覆盖)。

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

您需要use语句导入它,例如:

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;

希望这有帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM