Enable Twig Extentions in Symfony2

Twig extentions is included by default in the vendors but to enable one of them like the Text (to be able to use nl2br) add the following to your app/config/config.yml

        class: Twig_Extensions_Extension_Text 
            - { name: twig.extension }

Virtual Host and Symfony2

It is always good to set up a virtual host for your project when you are developing an application. Here is an example of two virtual hosts that I have set up for two of my projects. One called crm and one called blog and both projects are located under /Users/sfprojects/

This is what I have added to the end of my httpd.conf

# Be sure to only have this line once in your configuration

# This is the configuration for your project

	ServerName crm
  DocumentRoot "/Users/sfprojects/crm/web"
   DirectoryIndex app.php

    AllowOverride All
    Allow from All

	ServerName blog
  DocumentRoot "/Users/sfprojects/blog/web"
   DirectoryIndex app.php

    AllowOverride All
    Allow from All

and this is what i have added to my /etc/hosts file crm blog

Happy hacking!

Symfony2 and .gitignore

*Updated 29th october 2012*
Here are the settings i use for my .gitignore in a symfony project.

Generic ignores:

## generic files to ignore

IDE files are personal and not interesting for other people:

## IDE files to ignore

Symfony specific ignore files:

# Symfony files to ignore

Everything is pretty simple but the Symfony ignore part perhaps needs some explanation. The obvious is the cache and the log directories, no need to store them.

The vendor dir is downloaded with the

.bin/vendors install

and it also install the files in web/bundles. IMPORTANT This is only true if you add new bundles to it through the deps file and not with git directly they will be downloaded. For an example of how to add a bundle to the deps file have a look here.

The most important file to ignore is the app/config/parameters.ini it contains your database settings and should not be shared with git.

Installing Symfony2

Here is a small video of how to install Symfony2 with git version control. My first video tutorial in years and I mumble a bit but I hope someone likes it ;).

The following commands where used:

To install the vendors use

php bin/vendors install

Clear the cache and the logs

rm -rf app/cache/*
rm -rf app/logs/*

Set up permissions

sudo chmod +a "www-data allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
sudo chmod +a "yourname allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs


Symfony2 and Timestampable example

To add Timestampable behaviour you need to add DoctrineExtentions to your app see my previous post Symfony2 and DoctrineExtensions for information of how to do that.

You need to add the following in the top of the Entity

use Gedmo\Mapping\Annotation as Gedmo;

and then you can use it like this in your entity:

 * @var datetime $updated
 * @ORM\Column(name="updated", type="datetime")
 * @Gedmo\Timestampable
private $updated;

Available configuration options: – on – is main option and can be create, update, change this tells when it should be updated – field – only valid if on=”change” is specified, tracks property for changes – value – only valid if on=”change” is specified, if tracked field has this value then it updates timestamp

Here is an example of setting the value on creation:

 * @var datetime $created
 * @ORM\Column(name="created", type="datetime")
 * @Gedmo\Timestampable(on="create")
private $created;

For more info: