我的探查器工具栏未出现在symfony 4.3.1中

Maj*_*0od 8 php symfony symfony4

在我的.env文件中,我已将我的应用程序环境指定为dev和debug,如下所示:

APP_ENV=dev
APP_DEBUG=true
Run Code Online (Sandbox Code Playgroud)

在我的config/packages/dev/web_profiler.yaml文件中,我有以下内容:

web_profiler:
    toolbar: true
    intercept_redirects: false

framework:
    profiler: { only_exceptions: false }
Run Code Online (Sandbox Code Playgroud)

其中的路由config/routes/dev/web_profiler.yaml似乎很好:

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

web_profiler_profiler:
    resource: '@WebProfilerBundle/Resources/config/routing/profiler.xml'
    prefix: /_profiler
Run Code Online (Sandbox Code Playgroud)

因此,当我运行服务器时,symfony server:start一切都很好,但没有显示探查器。我是否错过了在Symfony中启用该功能的功能?

为了澄清,该页面正在输出具有适当内容的适当HTML页面。只是没有显示探查器。


我的基本树枝模板:

<!DOCTYPE html>
<html lang="en" dir="ltr">
    <head>
        <meta charset="utf-8">
        <title>{% block title %} {% endblock %}</title>
        {{ encore_entry_script_tags('base') }}
        <link rel="icon" type="image/x-icon" href="{{ asset('build/images/favicon.ico') }}" />
        <link href="https://fonts.googleapis.com/css?family=IBM+Plex+Sans:400,500|Playfair+Display:400,700&display=swap" rel="stylesheet">
        {{ encore_entry_link_tags("base") }}
        {% block stylesheet %}{% endblock %}
    </head>
    <body {% if app.request.get('_route') == 'home' %} class='homepage' {% endif %} >
        <header>
            <div id='top-navigation' class='padding-lg__left-md padding-lg__right-md padding-lg__top-sm padding-lg__bottom-sm row row__align-center row__justify-start'>
                <span class='text-color__white text-size__small text-weight__bold margin-lg__right-lg'>Our Mission</span>
                <span class='text-color__white text-size__small text-weight__bold margin-lg__right-lg'>Our Team</span>
                <span class='text-color__white text-size__small text-weight__bold margin-lg__right-lg'>Where the Money Goes</span>
                <span class='text-color__white text-size__small text-weight__bold margin-lg__right-lg'>Community Leadership</span>
                <span class='text-color__white text-size__small text-weight__bold'>Policies</span>
                <span class='text-color__white text-size__small text-weight__bold margin-lg__left-auto icon-set'> <span class='icon size__small color__white margin-lg__right-xsm'>{{ source('@public_path'~asset('build/images/icons/feedback.svg')) }}</span>Submit Feedback</span>
            </div>
            <nav class="padding-lg__top-md padding-lg__bottom-md padding-lg__left-md padding-lg__right-md row row__align-center row__justify-start {% if app.request.get('_route') == 'home' %} homepage {% endif %}">
                <div id='logo'>
                    <a href="{{ url('home') }}">
                        <img src="{{ asset('build/images/logo_placeholder.png') }}" alt="logo">
                    </a>
                </div>
                {% if app.request.get('_route') == 'creator-register' %}

                {% else %}
                    {% if not is_granted('IS_AUTHENTICATED_FULLY') %}
                        <div class='margin-lg__left-auto'>
                            <a href="{{ url('login') }}">
                                <div class='icon-set'>
                                    <span class='icon margin-lg__right-xsm'>
                                        {{ source('@public_path'~asset('build/images/icons/user.svg')) }}
                                    </span>
                                    <span class='nav-item'>Login</span>
                                </div>
                            </a>
                        </div>
                    {% endif %}

                {% endif %}
            </nav>
        </header>
        {% if app.request.get('_route') != 'home' %} <div class='container is_top'> {% endif %}
            {% block body %} {% endblock %}
        {% if app.request.get('_route') != 'home' %} </div> {% endif %}
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

Security.yaml防火墙:

    firewalls:
            dev:
                pattern: ^/(_(profiler|wdt)|css|images|js)/
                security: false
            main:
                anonymous: true
                guard:
                    authenticators:
                        - App\Security\LoginFormAuthenticator
                logout:
                    path : logout
                remember_me:
                    secret: '%kernel.secret%'
                    lifetime: 2592000 #<- 30 days in seconds - defaults to one year if you take this out!
Run Code Online (Sandbox Code Playgroud)

结果php bin/console debug:router | grep _profiler

  _profiler_home             ANY      ANY      ANY    /_profiler/                        
  _profiler_search           ANY      ANY      ANY    /_profiler/search                  
  _profiler_search_bar       ANY      ANY      ANY    /_profiler/search_bar              
  _profiler_phpinfo          ANY      ANY      ANY    /_profiler/phpinfo                 
  _profiler_search_results   ANY      ANY      ANY    /_profiler/{token}/search/results  
  _profiler_open_file        ANY      ANY      ANY    /_profiler/open                    
  _profiler                  ANY      ANY      ANY    /_profiler/{token}                 
  _profiler_router           ANY      ANY      ANY    /_profiler/{token}/router          
  _profiler_exception        ANY      ANY      ANY    /_profiler/{token}/exception       
  _profiler_exception_css    ANY      ANY      ANY    /_profiler/{token}/exception.css 
Run Code Online (Sandbox Code Playgroud)

最后是首页控制器:

<?php
namespace App\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class HomepageController extends AbstractController{

    /**
    * @Route("/", name="home")
    */

    public function output(){
        return $this->render('homepage/home.html.twig',[
            'title' => 'yo',
        ]);
    }
}

?>
Run Code Online (Sandbox Code Playgroud)

添加了public / index.php:

<?php

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

require dirname(__DIR__).'/config/bootstrap.php';

if ($_SERVER['APP_DEBUG']) {
    umask(0000);

    Debug::enable();
}

if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
    Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}

if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
    Request::setTrustedHosts([$trustedHosts]);
}

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
Run Code Online (Sandbox Code Playgroud)

yiv*_*ivi 10

远程为您调试它是非常困难的,如果不是不可能的话。确切的问题与您本地设置中的某些特定内容有关,无法访问您的项目的人将没有机会确切地看到问题所在。

针对您的情况的一些通用和特定故障排除建议:

第一。重新安装分析器包

虽然不寻常,但安装可能会中断。确保您的分析器包没问题。

首先将其删除 ( composer remove profiler),然后重新安装:) composer require --dev profiler

第二。检查配置

使用 Symfony 的控制台命令来验证您的配置。

首先是内置分析器:

$ bin/console debug:config framework profiler
Run Code Online (Sandbox Code Playgroud)

应该返回如下内容:

Current configuration for "framework.profiler"
==============================================

only_exceptions: false
enabled: true
collect: true
only_master_requests: false
dsn: 'file:%kernel.cache_dir%/profiler'
Run Code Online (Sandbox Code Playgroud)

然后对于探查器工具栏:

$ bin/console debug:config web_profiler
Run Code Online (Sandbox Code Playgroud)

应该返回如下内容:

Current configuration for extension with alias "web_profiler"
=============================================================

web_profiler:
    toolbar: true
    intercept_redirects: false
    excluded_ajax_paths: '^/((index|app(_[\w]+)?)\.php/)?_wdt'
Run Code Online (Sandbox Code Playgroud)

第三。检查容器

检查 Profiler 服务将如何实例化:

$ bin/console debug:container profiler --show-arguments
Run Code Online (Sandbox Code Playgroud)

期待这样的事情:

Information for Service "profiler"
==================================

 Profiler.

 ---------------- -------------------------------------------------------------------------------------
  Option           Value
 ---------------- -------------------------------------------------------------------------------------
  Service ID       profiler
  Class            Symfony\Component\HttpKernel\Profiler\Profiler
  Tags             monolog.logger (channel: profiler)
                   kernel.reset (method: reset)
  Calls            add, add, add, add, add, add, add, add, add, add, add, add, add, add, add, add, add
  Public           yes
  Synthetic        no
  Lazy             no
  Shared           yes
  Abstract         no
  Autowired        no
  Autoconfigured   no
  Arguments        Service(profiler.storage)
                   Service(monolog.logger.profiler)
                   1
 ---------------- -------------------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

然后对于 web_toolbar:

# bin/console debug:container web_profiler.debug_toolbar --show-arguments
Run Code Online (Sandbox Code Playgroud)

对于这样的事情:

Information for Service "web_profiler.debug_toolbar"
====================================================

 WebDebugToolbarListener injects the Web Debug Toolbar.

 ---------------- ------------------------------------------------------------------------
  Option           Value
 ---------------- ------------------------------------------------------------------------
  Service ID       web_profiler.debug_toolbar
  Class            Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener
  Tags             kernel.event_subscriber
                   container.hot_path
  Public           no
  Synthetic        no
  Lazy             no
  Shared           yes
  Abstract         no
  Autowired        no
  Autoconfigured   no
  Arguments        Service(twig)

                   2
                   Service(router.default)
                   ^/((index|app(_[\w]+)?)\.php/)?_wdt
                   Service(web_profiler.csp.handler)
 ---------------- ------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

(注意2, 启用工具栏)。

4. 检查事件调度程序。

kernel.response事件期间注入 Web 调试工具栏。检查回调是否正确挂钩:

$ bin/console debug:event-dispatcher kernel.response
Run Code Online (Sandbox Code Playgroud)

这将返回如下内容:

Registered Listeners for "kernel.response" Event
================================================

 ------- -------------------------------------------------------------------------------------------- ----------
  Order   Callable                                                                                     Priority
 ------- -------------------------------------------------------------------------------------------- ----------
  #1      ApiPlatform\Core\Hydra\EventListener\AddLinkHeaderListener::onKernelResponse()               0
  #2      Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse()              0
  #3      Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelResponse()          0
  #4      Symfony\Component\WebLink\EventListener\AddLinkHeaderListener::onKernelResponse()            0
  #5      Symfony\Component\Security\Http\RememberMe\ResponseListener::onKernelResponse()              0
  #6      ApiPlatform\Core\HttpCache\EventListener\AddHeadersListener::onKernelResponse()              -1
  #7      Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelResponse()              -100
  #8      Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener::onKernelResponse()   -128
  #9      Symfony\Component\HttpKernel\EventListener\TestSessionListener::onKernelResponse()           -128
  #10     Symfony\Component\HttpKernel\EventListener\DisallowRobotsIndexingListener::onResponse()      -255
  #11     Symfony\Component\HttpKernel\EventListener\SessionListener::onKernelResponse()               -1000
  #12     Symfony\Component\HttpKernel\EventListener\StreamedResponseListener::onKernelResponse()      -1024
 ------- -------------------------------------------------------------------------------------------- ----------
Run Code Online (Sandbox Code Playgroud)

注意 item #7,它是 Profiler 收集器(其中包括X-Debug-Token响应中的标头,稍后将由 Web 调试工具栏检查,这是#8上面列表中的项目。

如果上述任何一项检查失败

你必须把重点放在特定部分,找出为什么它失败。也许其他一些捆绑干扰?配置文件之一有问题?

一切检查

......但仍然无法正常工作?嗯,这很奇怪。确保您返回的模板具有</body>标签,并且返回的响应具有text/html内容类型。但是,如果以上所有检查都通过......它应该可以工作。


在评论中,您说framework.profiler.collect在执行这些检查时设置为 false。

通过如下更改将其设置为 true config/packages/dev/web_profiler.yaml

framework:
    profiler:
        only_exceptions: false
        collect: true
Run Code Online (Sandbox Code Playgroud)

  • 突出的是:“debug:config Framework profiler”返回了“collect: false” (3认同)

小智 8

我也有这个问题。我是 Sympfony 的新手,我不知道,如果在 apache 上运行,则必须通过 Composer 需要 .htaccess。只需这样做:

composer require symfony/apache-pack
Run Code Online (Sandbox Code Playgroud)

就是解决方案。


小智 5

我在新的 Symfony 5.1 应用程序中遇到了类似的症状 - 即使项目处于调试模式,调试工具栏也不会显示在某些页面上。结果在这个应用程序中,我打算将标签<body></body>放在每个页面的树枝模板中,而不是在基本模板中。但对于一些页面(那些没有显示调试工具栏的页面),我忘记<body></body>在页面模板中包含标签,因此渲染的 HTML 没有<body>标签 - 因此调试工具栏不会显示。