Tutorial : Develop To-Do List App with Symfony2 – Part 1

Symfony2 has gained its pace and become more and more popular since year 2011. In order to get your hands on this new version of symfony framework, the best way is to develop a simple project and dive into it.

Today i share with you all my journey to learn symfony2, hope this will help for those are interested.


Step 1
In order to setup a project on your local PC/laptop, do download a copy of standard version with vendor of symfony zip file at

Extract the zip file to your local web server’s root directory or project folder.


Step 2
I rename the “Symfony” folder to the project name – “sf2todo“.

So the basic structure for the “sf2todo” project will be as below:

www/ <- your web root directory
    sf2todo/ <- the unpacked archive


Step 3
Now you can configure your httpd apache config file and add the project configuration at the end of file.

# /etc/httpd/conf/httpd.conf


  ServerName sf2todo
  DocumentRoot "/var/www/sf2todo/web"
  DirectoryIndex app.php
  <Directory "/var/www/sf2todo/web">
    AllowOverride All
    Allow from All


Step 4
Next you need to a new domain line to the bottom of the host file located at /etc/hosts. (Tips: you need to edit using sudo privilege at linux server or run as administrator at windows)

# /etc/hosts     sf2todo


Step 5
Finally, you need to restart your apache by using following command:

#1 Linux

$ sudo service httpd restart


#2 Windows
Restart the apache using Services control panel.


Step 6
Symfony2 comes with a visual server configuration tester to help make sure your web server and PHP are configured to use Symfony. You can use the following URL to check your server configuration:


Try to fix those warnings or errors before proceed to next step.

symfony2 config page


Step 7
Click “Configure your Symfony Application Online” and will be redirected to the configuration page as below.

Here you need to fill up the database configuration.

Symfony Configure Database


Step 8
Click “Next Step” and you will see the Global Secret page where you can choose to generate or use the default generated secret key.

Symfony Global Secret Page


Step 9

Click “Next Step” and complete the process and it show the final configuration.

Symfony Completed Step


Step 10
Finally run command prompt and cd to sf2todo folder, now it is time to create a bundle named “ToDoBundle” for this application by typing following command at the command prompt:

 php app/console generate:bundle --namespace=Tsang/ToDoBundle --format=yml 

Symfony Creating Bundle

Just click Enter all the way for default settings till the bundle was generated successfully.

Symfony Creating Bundle Success


Step 11

Now we have to configure few files in order to get our basic landing page.

Open /app/config/routing.yml and write code as below:

# Internal routing configuration to handle ESI
#   resource: "@FrameworkBundle/Resources/config/routing/internal.xml"
#   prefix:   /_internal

 resource: "@TsangToDoBundle/Resources/config/routing.yml"

Then updated /app/config/routing_dev.yml as below :

 resource: "@AcmeDemoBundle/Controller/SecuredController.php"
 type:     annotation

 resource: "@AcmeDemoBundle/Controller/DemoController.php"
 type:     annotation
 prefix:   /demo

 resource: .
 type:     assetic

 resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"
 prefix:   /_wdt

 resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
 prefix:   /_profiler

 resource: "@SensioDistributionBundle/Resources/config/routing/webconfigurator.xml"
 prefix:   /_configurator

 resource: routing.yml

The new generated bundle structure :

Symfony new bundle structure

There are 3 files need to be updated:

1) /src/Tsang/ToDoBundle/Controller/DefaultController.php


namespace Tsang\ToDoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

class DefaultController extends Controller
* @Route("/")
* @Template()
  public function indexAction()
    return $this->render('TsangToDoBundle:Default:index.html.twig');

2) /src/Tsang/ToDoBundle/Resources/config/routing.yml

resource: "@TsangToDoBundle/Controller/DefaultController.php"
type:     annotation
prefix:   /

3) /src/Tsang/ToDoBundle/Resources/views/Default/index.html.twig

<div align="center">
 <h2>Welcome to Sf2Todo List by Terry Tsang!</h2>


Final Step
After all those steps above, you need to run below command to clear cache for both dev and prod environment:

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

You now can browse to http://sf2todo/ and have below temporary landing page.

Symfony to-Do List App Landing Page

If you are interested, remember to stay tuned for my next part of symfony2 tutorial, cheers!


Leave a Comment.