Too much data with var_dump in symfony2 doctrine2

后端 未结 9 1398
夕颜
夕颜 2020-11-28 02:37

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 variable

相关标签:
9条回答
  • 2020-11-28 03:05

    The get_object_vars() improve the visualization too.

    echo "<pre>";
    \Doctrine\Common\Util\Debug::dump(get_object_vars($user));
    
    0 讨论(0)
  • 2020-11-28 03:05

    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();
    
    0 讨论(0)
  • 2020-11-28 03:08

    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.

    0 讨论(0)
  • 2020-11-28 03:14

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

    0 讨论(0)
  • 2020-11-28 03:15

    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.

    0 讨论(0)
  • 2020-11-28 03:15

    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.

    0 讨论(0)
提交回复
热议问题