Monthly Archives: January 2011

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:

 

N

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

./console

you will see something like

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