Symfony2 docine2中使用 var_dump 的数据太多

我有大约40个实体和许多双向关系。 每当我使用 var _ dump ($user)或任何实体时,我的浏览器都会加载太多的数组和变量数据,然后它就崩溃了。

我想知道问题出在哪里。

数据插入正常。我能在生产中引起问题吗。

88996 次浏览

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.

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.

well formatted :

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

The get_object_vars() improve the visualization too.

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

Just use echo serialize($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();

Simple and easy example.

var_dump(serialize($Object));

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

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. enter image description here