2017-10-13 38 views
0

探查器不工作我做了symfony應用程序3.3新內核使用官方的文檔http://symfony.com/doc/current/configuration/multiple_kernels.htmlSymfony的使用多個內核

,但我犯了一個新的文件夾的API與所有的configs,並將此if語句app_dev和Web文件夾

應用

這是我的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-調試令牌,鏈接→http://localhost:8000/_profiler/5cb1d5

但是當我打開此探查器只顯示來自API的應用程序的內核沒有什麼可以幫助我的要求嗎?我是否缺少一些配置?

回答

0

可能是因爲如果你想啓用探查器,你的內核應該在'dev'環境中。和調試應運行enabled.Try:

$kernel = new ApiKernel('dev', true); 

編輯:(你應該打開新的問題,而不是完全地變化問題) 有2 posibility:

你不必路線的探查。在這種情況下,這個routing.yml文件添加到您:

_profiler: 
resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml" 
prefix: /_profiler 

或者,如果你不能達到探查數據也許有你的內核數的變化沒有被捕獲。在這種情況下,你應該遵循這個instruction和項目

而第三選項添加data_collector - 如果你重寫你的內核比你忘了添加探查包,儘量把它添加到您的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內核)

+0

我從app.php在app_dev.php複製的代碼我有這樣的,對不起,我錯將改變它 –

+0

剛編輯我的答案 –

+0

我要探查的路線,但也許我需要使用不同的分析器的API,因爲profiler與應用程序內核調用,是否有可能合併來自兩者的數據? –

0

你切換基於此條件下,內核:

if (strpos($_SERVER['REQUEST_URI'], 'api') !== false) 

但說到調用探查器路由[http://localhost:8000/_profiler/5cb1d5]您的REQUEST_URI不再符合條件,並且您被重定向到其他內核(您的案例中的應用程序)。