13

自 symfony 2.2 更新以来,web 调试工具栏不再加载到 app_dev.php 中。

我收到以下错误:

An error occurred while loading the web debug toolbar (404: Not Found).
Do you want to open the profiler?

在 prod.log 中,我得到以下信息:

request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /_profiler/84fb75cc3ffd5435474ebe4250e01fac2cdf49c1"" at /httpdocs/project/app/cache/prod/classes.php line 3597 [] []

request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /_wdt/452d5b4aa2dd9388285fa1c286d5c54218029c71"" at /httpdocs/priject/app/cache/prod/classes.php line 3597 [] []

我已经清除了几次缓存:)

有趣的是,在 /app_dev.php 页面上的所有链接都不再链接到 /app_dev.php。

当我手动修改url并将app_dev.php添加到url时,包括配置文件(/_profiler/5fdc27cb82c4e9e426b3ab27377deb0b760fdca2),分析器正确加载。

routing_dev.yml:

_assetic:
    resource: .
    type:     assetic

_wdt:
    resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"
    prefix:   /_wdt

_profiler:
    resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
    prefix:   /_profiler

_configurator:
    resource: "@SensioDistributionBundle/Resources/config/routing/webconfigurator.xml"
    prefix:   /_configurator

_main:
    resource: routing.yml

如果有任何帮助,我将不胜感激。

更新一:config_dev.yml

imports:
    - { resource: config.yml }

framework:
    router:   { resource: "%kernel.root_dir%/config/routing_dev.yml" }
    profiler: { only_exceptions: false }

web_profiler:
    toolbar: true
    intercept_redirects: false

monolog:
    handlers:
        main:
            type:  stream
            path:  %kernel.logs_dir%/%kernel.environment%.log
            level: debug
        firephp:
            type:  firephp
            level: info
        chromephp:
            type:  chromephp
            level: info

assetic:
    use_controller: true

更新二:AppKernel.php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new JMS\AopBundle\JMSAopBundle(),
            new JMS\DiExtraBundle\JMSDiExtraBundle($this),
            new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
            new myProject\MyBundle\myBundle(),
            new FOS\UserBundle\FOSUserBundle(),
            new myProject\MyBackendBundle\myBackendBundle(),
       );

        if (in_array($this->getEnvironment(), array('dev', 'test'))) {
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
        }

        return $bundles;
    }

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
    }
}

更新三:.htaccess

DirectoryIndex app.php

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^app\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]
    RewriteRule .? %{ENV:BASE}app.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 302 ^/$ /app.php/
    </IfModule>
</IfModule>

更新: 我发现了错误,它是模板中的错误(旧)渲染标签。:(

谢谢你的支持

4

8 回答 8

11

我也有这个问题,试着注意你的 .htaccess 并让它看起来像这样:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^app_dev.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]    ##### this is the part that you should tweak, have the .htaccess point the request to app_dev.php, since the routing.yml is empty initially
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]
    RewriteRule .? %{ENV:BASE}/app_dev.php [L]        ##### this is the part that you should tweak, have the .htaccess point the request to app_dev.php, since the routing.yml is empty initially
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        # When mod_rewrite is not available, we instruct a temporary redirect of
        # the startpage to the front controller explicitly so that the website
        # and the generated links can still be used.
        RedirectMatch 302 ^/$ /app.php/
        # RedirectTemp cannot be used instead
    </IfModule>
</IfModule>
于 2013-06-04T10:37:35.420 回答
5

在 Symfony 4 + Flex 我必须安装symfony/apache-packrecipie

composer req apache-pack
于 2017-12-15T20:19:26.777 回答
3

在新的 Linux 机器上安装我的应用程序后,我遇到了这个特殊问题。我刚刚忘记在 Apache2 中激活 mod_rewrite

[sudo] a2enmod rewrite
[sudo] service apache2 restart

希望它会有所帮助!

于 2015-03-12T21:00:45.667 回答
1

此错误的另一个来源:更新 Apache Web 服务器而不取消注释重写模块。通过实践学习!

于 2013-06-23T12:57:18.063 回答
1

当我修改供应商代码以进行调试时,我遇到了这个错误。(我确实知道这不是正确的方法,但无论如何......我做了修改,测试了 Web 应用程序并忘记了回滚供应商代码)。

如果是您的情况并且您不记得您对供应商代码进行了“非法”更改的确切位置,您可以删除供应商目录或其组件并运行php composer.phar update命令以提取原始版本。

于 2016-03-25T09:46:04.377 回答
0

您的重写规则可能是导致它的原因。就在不久前,我正在重写我的,我在分析器上遇到了同样的问题。

于 2013-04-27T17:02:29.437 回答
0

对我来说,当我更改 .htaccess(从 web 目录)以调用 app_dev.php 而不是 app.php 时,就会发生这种情况,但我没有在 .htaccess 文件中的任何地方更改它。将所有外观更改为 app_dev.php 后,错误消失了。

于 2016-09-20T13:19:29.973 回答
-6

只需重新启动您的 WAMP/LAMP,它对我有用。

于 2014-01-21T09:39:47.697 回答