【发布时间】:2020-02-23 21:27:12
【问题描述】:
在我的 .env 文件中,我已将我的应用程序环境指定为 dev 和 debug,如下所示:
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 页面。只是没有显示分析器。
我的基本树枝模板:
<!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
最后的主页控制器:
<?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);
【问题讨论】:
-
在您的浏览器中执行 ctrl-u 并验证您是否显示了一个 html 页面。该栏只会出现在实际页面中。
-
1.您可以检查浏览器的网络选项卡(ff 和 chrome 中的 F12),是否可能加载了一些 _profiler 路由? (如果是,它已加载但不可见)。 2. web profiler bundle 是否处于活动状态,运行
bin/console debug:event-dispatcher kernel.response,其中-128 优先级应该是WebDebugToolbarListener::onKernelResponse。如果不是,请检查 config/bundles.php,它应该包含 WebProfilerBundle。是的。 -
@Majo0od 如果您发现第 102 行中的条件导致侦听器停止工作,您有什么尝试进一步解决这个问题?以下哪一个条件的计算结果为
true? -
临时修改
WebDebugToolbarListener.php。在第 109 行,在 return 语句之前添加:echo 'Mode: ', $this->mode, " XDebTok: ", $response->headers->has('X-Debug-Token'), " IsRedir: ", $response->isRedirection(); die();并报告其返回。 -
在“config/packages/dev/web_profiler.yaml”的顶部添加一些虚假字符串(例如“abc”),看看是否有错误。也许文件根本没有被读取。