Skip to content

Commit afcd3e1

Browse files
committed
feature #340 Added an example of the dump() function (javiereguiluz)
This PR was squashed before being merged into the master branch (closes #340). Discussion ---------- Added an example of the dump() function This fixes #339. Commits ------- 8a5a49d Added an example of the dump() function
2 parents 3ca2b94 + 8a5a49d commit afcd3e1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/AppBundle/Controller/BlogController.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ public function indexAction($page)
5656
*/
5757
public function postShowAction(Post $post)
5858
{
59+
// Symfony provides a function called 'dump()' which is an improved version
60+
// of the 'var_dump()' function. It's useful to quickly debug the contents
61+
// of any variable, but it's not available in the 'prod' environment to
62+
// prevent any leak of sensitive information.
63+
// This function can be used both in PHP files and Twig templates. The only
64+
// requirement is to have enabled the DebugBundle.
65+
if ('dev' === $this->getParameter('kernel.environment')) {
66+
dump($post, $this->get('security.token_storage')->getToken()->getUser(), new \DateTime());
67+
}
68+
5969
return $this->render('blog/post_show.html.twig', array('post' => $post));
6070
}
6171

0 commit comments

Comments
 (0)