本文介绍了在Symfony 2(.7)中禁用不推荐使用的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从我的Symfony 2更新为2.7.我在PHPUnitconsole中得到了很多已弃用的错误(消息现在很清楚).

Since my Symfony 2 update to 2.7. I get a lot of deprecated erors in PHPUnit and console (message is clear by now).

ProjectX\ApiBundle\Tests\Controller\SectionsControllerTest::testPostDebug()
The twig.form.resources configuration key is deprecated since version 2.6 and will be removed in 3.0. Use the twig.form_themes configuration key instead.

有什么想法现在要禁用它们吗?

Any idea how to disable them for now?

推荐答案

我遇到了相同的问题,并通过下面的链接进行了解决. Symfony声明将报告所有错误,并按设计覆盖您在php.ini中放置的内容(否则它将无法捕获并为您显示漂亮的堆栈跟踪).

I have the same problem and solved it similar to the below link. Symfony declares to report all errors and overrides what you put in php.ini by design (otherwise it couldn't catch & display nice stack traces for you).

因此,您需要通过在AppKernel.php中创建init()函数并设置error_reporting想要的位置来覆盖Symfony2的内置错误报告,可能)进行一些环境检测,以确保您不会在生产中显示错误,例如:

So, you'll need to override Symfony2's built-in error reporting by creating an init() function in your AppKernel.php and setting the error_reporting how you'd like there, along with (probably) some environment detection to make sure you don't display errors in production, for example:

// Add this to app/AppKernel.php
public function init()
{
    if ($this->debug) {
        ini_set('display_errors', 1);
        error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
    } else {
        ini_set('display_errors', 0);
    }
}

此处有更多详细信息(如果您不阅读俄语,请使用Google翻译:) http ://tokarchuk.ru/2012/12/disable-deprecated-warnings-in-symfony-2/

More details here (use Google Translate if you do not read Russian :) http://tokarchuk.ru/2012/12/disable-deprecated-warnings-in-symfony-2/

这篇关于在Symfony 2(.7)中禁用不推荐使用的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 17:13