Search This Blog

Tuesday, January 15, 2013

Developing Symfony 2

I started using Symfony as a php framework when it was at version 1.4.
Developed by Sensio Labs I chose it over other php frameworks primarily because of the excellent quality of it's documentation.
As I was using it I found all that I needed - additional utilities are mature - developed, tested, documented and ready for use. Version 1.4 was the last release of Symfony version 1.
Symfony 2 is a major update from version 1 and the changes do take some getting used to.
Also some features commonly used in v1.4 are not yet present in version 2.

This post is based on version 2.4.1

Installation.

Symfony 2 uses git and composer to download the framework itself and vendor files.

See installation.html  in particular to add a new library (under vendors).
Note - if downloaded/cloned a fresh Symfony distribution to start a new application, rember to initialise git (or subsequent git submodule downloads won't work) eg:
git init

The steps are:
edit composer.json
add an entry under require:
"require": {
         ...
        "gedmo/doctrine-extensions":      "master-dev"
    },

Get composer if not already done:
 curl -s https://getcomposer.org/installer | php 
Then run  composer.phar to update:
php composer.phar update

done.
Typical httpd conf entry:
<VirtualHost *:80>
  DocumentRoot "/Users/johnreidy/sfprojects/sftest/web"
  ServerName sftest
  DirectoryIndex index.php

  <Directory "/Users/johnreidy/sfprojects/sftest/web">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Allow from All
  </Directory>
php_value error_log "/Users/johnreidy/sfprojects/php.log"
</VirtualHost>

Once installed you can run
http://sftest/app_dev.php to show the site.

First Bundle.

From the Symfony 2 book: Page creation
Create a bundle
app/console generate:bundle --namespace=Test/WebsiteBundle --format=yml
In addtionl to loading the bundle in app/AppKernel.php it will also and a pointer to a bundle routing file in app/config/routing.yml.
To add a new page, add to the bundle routing file src/Test/WebsiteBundle/Resources


No comments:

Post a Comment