概述 快速入门 教程 手册 最佳实践 组件 参考 贡献

发布于 2015-08-27 16:23:30 | 296 次阅读 | 评论: 0 | 来源: 网络整理

When you work on a Symfony project on your local machine, you should use the dev environment (app_dev.php front controller). This environment configuration is optimized for two main purposes:

  • Give the developer accurate feedback whenever something goes wrong (web debug toolbar, nice exception pages, profiler, ...);
  • Be as similar as possible as the production environment to avoid problems when deploying the project.

Disabling the Bootstrap File and Class Caching

And to make the production environment as fast as possible, Symfony creates big PHP files in your cache containing the aggregation of PHP classes your project needs for every request. However, this behavior can confuse your IDE or your debugger. This recipe shows you how you can tweak this caching mechanism to make it friendlier when you need to debug code that involves Symfony classes.

The app_dev.php front controller reads as follows by default:

// ...

$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';

$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
$request = Request::createFromGlobals();

To make your debugger happier, disable all PHP class caches by removing the call to loadClassCache() and by replacing the require statements like below:

// ...

// $loader = require_once __DIR__.'/../app/bootstrap.php.cache';
$loader = require_once __DIR__.'/../app/autoload.php';
require_once __DIR__.'/../app/AppKernel.php';

$kernel = new AppKernel('dev', true);
// $kernel->loadClassCache();
$request = Request::createFromGlobals();

小技巧

If you disable the PHP caches, don’t forget to revert after your debugging session.

Some IDEs do not like the fact that some classes are stored in different locations. To avoid problems, you can either tell your IDE to ignore the PHP cache files, or you can change the extension used by Symfony for these files:

$kernel->loadClassCache('classes', '.php.cache');
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务