我使用官方文档http://symfony.com/doc/current/configuration/multiple_kernels.html
在symfony应用程序3.3上创建了一个新内核但我用所有配置创建了一个新文件夹api,并将此if语句添加到app_dev和web文件夹中的app
这是我的app_dev.php文件
<?php
use Symfony\Component\Debug\Debug;
use Symfony\Component\HttpFoundation\Request;
require_once(__DIR__.'/../c3.php');
// If you don't want to setup permissions the proper way, just uncomment the following PHP line
// read https://symfony.com/doc/current/setup.html#checking-symfony-application-configuration-and-setup
// for more information
//umask(0000);
// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'], true) || PHP_SAPI === 'cli-server')
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
require __DIR__.'/../vendor/autoload.php';
Debug::enable();
if (strpos($_SERVER['REQUEST_URI'], 'api') !== false) {
$kernel = new ApiKernel('dev', true);
} else {
$kernel = new AppKernel('dev', true);
}
if (PHP_VERSION_ID < 70000) {
$kernel->loadClassCache();
}
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
这也可以正常工作,但是当我在api内核时,symfony调试栏说它无法连接到探查器,当我从api服务器和头文件得到响应时
X-Debug-Token-Link→http://localhost:8000/_profiler/5cb1d5
但是当我打开这个探查器只显示来自app内核的请求api你能帮助我吗?我错过了一些配置吗?
答案 0 :(得分:0)
可能因为如果你想启用探查器,你的内核应该在'dev'环境中。并且应该启用debug.Try:
$kernel = new ApiKernel('dev', true);
编辑:(你应该打开新问题而不是完全改变问题) 有2个可能性:
您没有指向探查器的路线。在这种情况下,请将此添加到routing.yml:
_profiler:
resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
prefix: /_profiler
或者,如果您无法在分析器中访问数据,那么您的内核中可能会有一些未被捕获的更改。在这种情况下,您应该遵循此instruction并在项目中添加data_collector
第三个选项 - 如果你重写内核而忘记添加Profiler包,请尝试将其添加到registerBundles()方法中:
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
if ('dev' === $this->getEnvironment()) {
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
$bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
}
}
(采用新鲜的sf内核)
答案 1 :(得分:0)
您根据这种情况切换内核:
if (strpos($_SERVER['REQUEST_URI'], 'api') !== false)
但是,当涉及调用探查器路由[http://localhost:8000/_profiler/5cb1d5]时,您的REQUEST_URI不再适合该条件,并且您被重定向到另一个内核(在您的情况下为应用程序)。