在我的 .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
:
_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',
]);
}
}
?>
添加了 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);
最佳答案
远程为您调试此问题即使不是不可能,也是非常困难的。确切的问题与您本地设置中的特定内容有关,无法访问您的项目的人将没有机会确切地看到问题所在。
针对您的情况的一些一般和具体的故障排除建议:
第一。重新安装分析器包
虽然不寻常,但安装可能会失败。确保您的分析器包没问题。
首先删除它( 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
期间注入(inject)的。事件。检查回调是否已正确 Hook :
$ 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
关于php - 我的分析器工具栏未显示在 symfony 4.3.1 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58593887/