diff --git a/book/templating.rst b/book/templating.rst index 1195b1244ab..a9e23ef0045 100644 --- a/book/templating.rst +++ b/book/templating.rst @@ -1487,12 +1487,33 @@ in a JavaScript string, use the ``js`` context: Debugging --------- -When using PHP, you can use :phpfunction:`var_dump` if you need to quickly find -the value of a variable passed. This is useful, for example, inside your -controller. The same can be achieved when using Twig thanks to the debug -extension. +When using PHP, you can use the +:ref:`dump() function from the VarDumper component ` +if you need to quickly find the value of a variable passed. This is useful, +for example, inside your controller:: -Template parameters can then be dumped using the ``dump`` function: + // src/AppBundle/Controller/ArticleController.php + namespace AppBundle\Controller; + + // ... + + class ArticleController extends Controller + { + public function recentListAction() + { + $articles = ...; + dump($articles); + + // ... + } + } + +.. note:: + + The output of the ``dump()`` function is then rendered in the web developer + toolbar. + +The same mechanism can be used in Twig templates thanks to ``dump`` function: .. code-block:: html+jinja diff --git a/components/var_dumper/introduction.rst b/components/var_dumper/introduction.rst index 6f43b67ef3d..8f265755c22 100644 --- a/components/var_dumper/introduction.rst +++ b/components/var_dumper/introduction.rst @@ -20,6 +20,8 @@ You can install the component in 2 different ways: * :doc:`Install it via Composer ` (``symfony/var-dumper`` on `Packagist`_); * Use the official Git repository (https://github.com/symfony/var-dumper). +.. _components-var-dumper-dump: + The dump() Function -------------------