我的分析工具栏在symfony 4.3.1中不显示

bkkx9g8r  于 11个月前  发布在  其他
关注(0)|答案(7)|浏览(143)

在我的.env文件中,我已经将我的应用环境指定为dev,并将debug指定为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运行服务器时,一切都很好,但是没有出现性能分析器。
澄清一下,页面输出的是一个包含适当内容的正确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>


安全.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上的结果:

_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


最后主页控制器:

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

?>


添加了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);

km0tfn4u

km0tfn4u1#

我也遇到了这个问题。我是Sympfony的新手,我不知道,如果在Apache上运行,.htaccess必须通过composer才能使用。简单地这样做:

composer require symfony/apache-pack

字符串
就是解决办法

uplii1fm

uplii1fm2#

我有一个类似的症状,在一个新的Symfony 5.1应用程序-调试工具栏不显示在某些页面上,即使该项目是在调试模式。原来在这个应用程序中,我打算有<body></body>标签内的树枝模板为每个页面,而不是在基本模板。但对几个页面(那些没有显示调试工具栏的),我忘记在页面模板中包含<body></body>标签,所以呈现的HTML没有<body>标签-因此调试工具栏将不会显示。

ddhy6vgd

ddhy6vgd3#

通过HTTP而不是HTTPS访问本地站点时也可能发生这种情况,这可能会导致工具栏请求失败。
通过浏览器开发工具的请求选项卡进行检查。如果请求被阻止,您可能会错过proxy configuration(来自此问题):

framework:
    trusted_proxies: '127.0.0.1,REMOTE_ADDR'

字符串

5m1hhzi4

5m1hhzi44#

如果你一直收到一个“正在加载...”的消息(或类似的东西),请检查身份验证是否正确。
从旧的Guard System to the new Security System迁移,我破坏了身份验证机制(以及匿名用户的处理),这导致调试工具栏无法加载。

falq053o

falq053o5#

如果您使用Apache而不是Symfony Server,则必须首先安装Apache包:

composer require symfony/apache-pack

字符串
其次,确保Apache mod_rewrite已启用。在Debian或Debian like OS中,您可以这样做:

sudo a2enmod rewrite


最后,在Apache编辑apache2.conf时允许覆盖,例如:

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>


注意“允许所有”而不是“允许无”

6uxekuva

6uxekuva6#

尝试使用命令:

composer dump-env dev

字符串

vxbzzdmp

vxbzzdmp7#

如果不是不可能的话,远程调试是非常困难的。确切的问题与本地设置中的某些特定内容有关,无法访问您的项目的人将没有机会看到确切的错误。
针对您的情况提供一些一般和具体的故障排除建议:

第一个.配置分析器包

虽然不寻常,安装可能会被破坏。确保你的分析器包是正确的。
首先删除它(composer remove profiler),然后再次安装它(composer require --dev profiler)。

2.检查配置

使用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'

3.检查容器

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


(Note 2,用于启用工具栏)。

4.检查事件调度器。

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

$ 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标头,稍后将由Web服务器检查,这是上面清单中的项#8)。

如果以上检查失败

你必须关注那个特定的部分来找出失败的原因。也许是其他的包干扰了?或者是某个配置文件的问题?

一切都核对无误

.但仍然不工作?嗯,这很奇怪。确保您返回的模板具有</body>标记,并且返回的响应具有text/html内容类型。但是如果以上所有检查都通过.它应该可以工作。
在注解中,您说在执行这些检查时,framework.profiler.collect被设置为false。
通过像这样更改config/packages/dev/web_profiler.yaml将其设置为true:

framework:
    profiler:
        only_exceptions: false
        collect: true

相关问题