繁体   English   中英

我的探查器工具栏未显示在 symfony 4.3.1 中

[英]My profiler toolbar isn't showing up in symfony 4.3.1

在我的.env文件中,我已将我的应用程序环境指定为 dev 并将调试设置为 true,如下所示:

APP_ENV=dev
APP_DEBUG=true

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

web_profiler:
    toolbar: true
    intercept_redirects: false

framework:
    profiler: { only_exceptions: false }

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

因此,当我使用symfony server:start运行服务器时,一切都很好,但分析器没有出现。 我错过了在 Symfony 中启用该功能的东西吗?

为澄清起见,该页面正在输出具有适当内容的正确 HTML 页面。 只是没有分析器出现。


我的基地 twig 模板:

<!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>

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!

结果php bin/console debug:router | grep _profiler 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 

最后主页controller:

<?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',
        ]);
    }
}

?>

添加公共/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);

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

针对您的情况的一些一般和具体的故障排除建议:

第一个。 重新安装分析器包

虽然不寻常,但安装可能会失败。 确保您的分析器 package 没问题。

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

第二。 检查配置

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

首先是内置分析器:

$ bin/console debug:config framework profiler

应该返回如下内容:

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

only_exceptions: false
enabled: true
collect: true
only_master_requests: false
dsn: 'file:%kernel.cache_dir%/profiler'

然后对于探查器工具栏:

$ bin/console debug:config web_profiler

应该返回如下内容:

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

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

第三。 检查容器

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

$ bin/console debug:container profiler --show-arguments

期待这样的事情:

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
 ---------------- -------------------------------------------------------------------------------------

然后对于 web_toolbar:

# bin/console debug:container web_profiler.debug_toolbar --show-arguments

对于这样的事情:

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)
 ---------------- ------------------------------------------------------------------------

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

第四。 检查事件调度程序。

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

$ bin/console debug:event-dispatcher kernel.response

这将返回如下内容:

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
 ------- -------------------------------------------------------------------------------------------- ----------

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

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

您必须专注于该特定部分以找出它失败的原因 也许其他一些捆绑干扰? 配置文件之一有问题?

一切都检查出来

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


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

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

framework:
    profiler:
        only_exceptions: false
        collect: true

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

composer require symfony/apache-pack

是解决方案。

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

当通过 HTTP 而不是 HTTPS 访问您的本地站点时,也会发生这种情况,这可能会使工具栏请求失败。

通过查看浏览器开发工具的请求选项卡进行检查。 如果请求被阻止,您可能会错过代理配置(来自此问题):

framework:
    trusted_proxies: '127.0.0.1,REMOTE_ADDR'

我在这个问题上挣扎了很长时间,但遮阳篷实际上非常简单。 您的模板必须包含<body>标签才能显示工具栏。 我只是在尝试 Symfony 并没有费心将它包含在我的 twig 文件中

您在结束body标记之前缺少javascripts块,例如:

  {% block javascripts '' %}
  </body>
</html>

探查器将一些脚本放入该块中。 这就是它不显示的原因。

此外,您应该在head中有stylesheets块。 你被命名为stylesheet

如果您不断收到“正在加载...”消息(或类似消息),请检查身份验证是否正常工作。

从旧的Guard System 迁移到新的 Security System我破坏了身份验证机制(以及匿名用户的处理),这导致调试工具栏没有被加载。

尝试使用命令:

composer dump-env dev

暂无
暂无

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

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