Symfony 2 - 加载Web调试工具栏时出错(404:Not Found)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Symfony 2 - 加载Web调试工具栏时出错(404:Not Found)相关的知识,希望对你有一定的参考价值。

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

我收到以下错误:

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 SymfonyComponentHttpKernelExceptionNotFoundHttpException: "No route found for "GET /_profiler/84fb75cc3ffd5435474ebe4250e01fac2cdf49c1"" at /httpdocs/project/app/cache/prod/classes.php line 3597 [] []

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

我已多次清除缓存:)

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

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

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

更新II:AppKernel.php

use SymfonyComponentHttpKernelKernel;
use SymfonyComponentConfigLoaderLoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            new SymfonyBundleFrameworkBundleFrameworkBundle(),
            new SymfonyBundleSecurityBundleSecurityBundle(),
            new SymfonyBundleTwigBundleTwigBundle(),
            new SymfonyBundleMonologBundleMonologBundle(),
            new SymfonyBundleSwiftmailerBundleSwiftmailerBundle(),
            new SymfonyBundleAsseticBundleAsseticBundle(),
            new DoctrineBundleDoctrineBundleDoctrineBundle(),
            new SensioBundleFrameworkExtraBundleSensioFrameworkExtraBundle(),
            new JMSAopBundleJMSAopBundle(),
            new JMSDiExtraBundleJMSDiExtraBundle($this),
            new JMSSecurityExtraBundleJMSSecurityExtraBundle(),
            new myProjectMyBundlemyBundle(),
            new FOSUserBundleFOSUserBundle(),
            new myProjectMyBackendBundlemyBackendBundle(),
       );

        if (in_array($this->getEnvironment(), array('dev', 'test'))) {
            $bundles[] = new SymfonyBundleWebProfilerBundleWebProfilerBundle();
            $bundles[] = new SensioBundleDistributionBundleSensioDistributionBundle();
            $bundles[] = new SensioBundleGeneratorBundleSensioGeneratorBundle();
        }

        return $bundles;
    }

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

更新III:.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>

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

感谢您的支持

答案

我也遇到过这个问题,请注意你的.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>
另一答案

在Symfony 4 + Flex中我必须安装qazxsw poi食谱

symfony/apache-pack
另一答案

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

composer req apache-pack

希望它会有所帮助!

另一答案

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

另一答案

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

如果是您的情况并且您不记得您对供应商代码进行了“非法”更改,您可以删除供应商目录或其组件并运行[sudo] a2enmod rewrite [sudo] service apache2 restart 命令来提取原始版本。

另一答案

你的重写规则可能会导致它。就在不久之前,我正在改写我的,我和探查器有同样的问题。

另一答案

对我来说,当我改变.htaccess(来自web目录)以便调用app_dev.php而不是app.php时会发生这种情况,但我没有在.htaccess文件中随处更改它。更改后,所有外观都以app_dev.php错误消失了。

另一答案

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

以上是关于Symfony 2 - 加载Web调试工具栏时出错(404:Not Found)的主要内容,如果未能解决你的问题,请参考以下文章

Symfony Route 中断调试工具栏

无法安装探查器symfony flex

Symfony4加载类自定义文件夹时出错“预计找到类...但是找不到它”

symfony2显示调试工具栏

Symfony 5 调试工具栏未显示在错误页面上

运行命令doctrine:schema:update symfony时出错