Using the Symfony VarDumper Component For Debugging

What is the Symfony VarDumper Component?

The VarDumper component provides mechanisms for walking through any arbitrary PHP variable. Built on top, it provides a better dump() function that you can use instead of var_dump.

Please visit the official documentation page for more detailed information about this Symfony component.

How can I install the Symfony VarDumper Component?

The quickest and easiest way is to find the package on packigst website and then use composer to install the package to your project.

To install to your project, run the following command on either Windows or Linux in the command line.

composer require symfony/var-dumper

This will add the current stable package to your project and will generate an updated autoload.php file in your vendors folder.

How do I use the Symfony VarDumper Component?

To use the VarDumper component, you must make some small changes to your AppKernel.php file, you will find this in your projects app folder.

Find the following section of code:

if( in_array($this->getEnvironment(), array('dev', 'test')) ){

    $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
    $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();


Now add to the code as shown in the example below:

if( in_array($this->getEnvironment(), array('dev', 'test')) ){
    $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle()
    $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
    //add the line below
    $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();


This will now allow you to use the VarDumper Component in your project and output information to the profiler bar.

This component can be used in your project files as the method dump()  is globally available from the component, you can also use the component in the command line interface too and the output will be written to STDOUT .

How to Use the Dump Method

If for example I had an entity in my project called Order and I was wanting to view the loaded entity from the database, the easiest way of achieving this would be like so:

$order = $this->getDoctrine()->getRepository('DemoCoreBundle:Order')->find(12345);

Resulting in the following output to the profiler bar:

Symfony Profiler Dump

This is quite a useful Symfony component and can be used in any project whether it is Symfony based or not, as long as it is a PHP project, go away and play with it, enjoy!

Using the Symfony Console Component To Improve Development & Deployment

What is the Symfony Console Component?

The Console component allows you to create command-line commands. Your console commands can be used for any recurring task, such as cronjobs, imports, or other batch jobs.

Please visit the official documentation page for more detailed information about this Symfony component.

How do I use the Symfony Console Component?

You can use the Symfony Console Component in either Windows Command Prompt (CMD) or Linux  Command Line Interface (CLI), the commands will work the same for both operating systems.

You will need to make sure PHP is in your PATH variable on Windows first.

Example Console Command

php app/console command:action --argumentName=argumentValue ...

Clearing the Production Cache

If for example you wanted to clear and warmup the cache for the production environment, you would execute the following commands:

php app/console cache:clear --env=prod
php app/console cache:warmup --env=prod

Now you should have your cache cleared and rebuilt ready to show any updates if you received no errors.

Make sure you do your database migrations before you clear your cache, as this will cause errors on the frontend of your site if you have schema changes.

Hopefully you are using database migrations for your project… you are using them right? I thought so…

Dumping Your Assetic Files

If you use the Assetic bundle in your projects, here is an example of how you would regenerate the assetic cache after making changes during development:

php app/console assetic:dump

That’s all you need to do to update your cached files.

I will add some more examples of the Symfony Console usage to future posts.