Posts

Showing posts from February 14, 2013

create and execute a command in symfony 2

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. Symfony 2 is mainly used to create web application, however, sometimes you need to extend your app and need a command line tool to help perform tasks around the application. It's one of the most stable parts of the framework and many people have already been using it for several months in many projects as it makes it really easy to develop this kind of software. And of course, everything is done in a really cool way, as many of the parts of Symfony2. Let’s see how can extremely easy create a new Command Task and custom our output. Create a file in Command Folder, for instance NewsletterCommand.php and fill it with an empty Command structure as follows <?php namespace Ankit\News