How to create a command (task) in Symfony 2

This tutorial is deprecated. It was written when Symfony2 was in beta. 

In Symfony 1.x a task is a command line tool to help perform tasks around the application. The same is in Symfony 2. Unfortunately in Symfony2 there is no tool to auto-generate some code for these. To create a Symfony2 Command you must to have or to create in your Bundle a folder named Command. Here, you must create a file named MytaskCommand.php with the following code:



ow, you can open a console and go to app folder. If you write:


you will see something like

You can execute this Command with: ./console tudorica:razvan


3 thoughts on “How to create a command (task) in Symfony 2

  1. razvan Post author

    this “how to” is from the time when symfony2 was in beta, so it is possible to not work anymore. please check documentation.

  2. Anonymous

    Just copy an existing task from a vendor bundle (e.g. Doctrine or swiftmailer) of the Symfony2 stable release to your own bundle’s Command directory and you have a nice and up-to-date template for your own command.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.