Too much data with var_dump in symfony2 doctrine2

被刻印的时光 ゝ 提交于 2019-11-26 21:31:10
mgiagnoni

Replace var_dump() with the debug method dump() provided by Doctrine Common.

\Doctrine\Common\Util\Debug::dump($user);

It works for single objects and Doctrine collections and should prevent browser displaying issues you are having.

well formatted :

echo '<pre>';
\Doctrine\Common\Util\Debug::dump($user, $recurciveLevelToDisplay);
echo '</pre>';

Simple and easy example.

var_dump(serialize($Object));

Symfony < 2.6

You can use \Doctrine\Common\Util\Debug::dump($variable, $depth); it displays doctrine output without the proxy information.

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.

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.

The get_object_vars() improve the visualization too.

echo "<pre>";
\Doctrine\Common\Util\Debug::dump(get_object_vars($user));

With Symfony 2.6 you can now just use dump($var) in your controller and {{ dump(var) }} in twig.

Make sure to add this to your AppKernal.php file, in the array('dev', 'test') section.

$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();

use dump($user) and you can see perfect result in Symfony Profiler! good luck

Just use echo serialize($user);

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!