php symfony2 学说 2 中的 var_dump 数据过多
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11902099/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Too much data with var_dump in symfony2 doctrine2
提问by Mirage
I have around 40 entities and many bidirectional relationships. Whenever i use var_dump($user) or any entity my browser gets loaded with too much data of arrays and variables then it just crashed.
我有大约 40 个实体和许多双向关系。每当我使用 var_dump($user) 或任何实体时,我的浏览器都会加载过多的数组和变量数据,然后它就会崩溃。
i want to whats the problem.
我想知道有什么问题。
The data is being inserted fine. Can i cause issue in production.
数据插入正常。我可以在生产中引起问题吗?
回答by mgiagnoni
Replace var_dump()with the debug method dump()provided by Doctrine Common.
将var_dump()替换为Doctrine Common提供的调试方法dump()。
\Doctrine\Common\Util\Debug::dump($user);
It works for single objects and Doctrine collections and should prevent browser displaying issues you are having.
它适用于单个对象和 Doctrine 集合,并应防止浏览器显示您遇到的问题。
回答by Bouchehboun Saad
well formatted :
格式正确:
echo '<pre>';
\Doctrine\Common\Util\Debug::dump($user, $recurciveLevelToDisplay);
echo '</pre>';
回答by Kentaro Ohkouchi
Simple and easy example.
简单易行的例子。
var_dump(serialize($Object));
回答by goto
Symfony < 2.6
Symfony < 2.6
You can use \Doctrine\Common\Util\Debug::dump($variable, $depth);it displays doctrine output without the proxy information.
您可以使用\Doctrine\Common\Util\Debug::dump($variable, $depth);它显示没有代理信息的学说输出。
Symfony > 2.6
Symfony > 2.6
If you are using symfony 2.6 or more, I strongly advice you to use dump().
It shows a well formated and colored output, and you can dynamically expend/hide rows.

如果您使用的是 symfony 2.6 或更高版本,我强烈建议您使用dump(). 它显示了格式良好的彩色输出,您可以动态扩展/隐藏行。

回答by Rad80
The problem is that in a bidirectional relationship both entities have a link to each other, so while displaying entity1 var_dump will also have to print all properties of entity2, which include entity1 itself giving you a loop.
问题在于,在双向关系中,两个实体之间都有一个链接,因此在显示 entity1 时 var_dump 还必须打印 entity2 的所有属性,其中包括 entity1 本身给您一个循环。
回答by Wellington Lorindo
The get_object_vars() improve the visualization too.
get_object_vars() 也改进了可视化。
echo "<pre>";
\Doctrine\Common\Util\Debug::dump(get_object_vars($user));
回答by Vitaly Pugach
use dump($user) and you can see perfect result in Symfony Profiler! good luck
使用 dump($user) 你可以在 Symfony Profiler 中看到完美的结果!祝你好运
回答by J-who
With Symfony 2.6 you can now just use dump($var) in your controller and {{ dump(var) }} in twig.
使用 Symfony 2.6,您现在可以在控制器中使用 dump($var) 并在 twig 中使用 {{ dump(var) }} 。
Make sure to add this to your AppKernal.php file, in the array('dev', 'test') section.
确保将此添加到您的 AppKernal.php 文件中的 array('dev', 'test') 部分。
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
回答by AlexM
Just use echo serialize($user);
只需使用 echo serialize($user);

