Nerds who love the symfony-project
1 Dec
Just a quick note to let everyone know that 1.2 is out… We’re really looking forward to running the new admin generator through it’s paces for a start…
The post from Fabien is here.
4 Nov
If you haven’t already heard Francois Zaninotto who was one of the authors of the Symfony book and who also contributed to Symfony by being a core team member has announced that he will no longer be contributing to the Symfony framework.
From all the team here at Symfonynerds, we just wanted to say a big thanks to Francois for all his contributions to Symfony. As readers of the book, his documentation has helped in many ways.
From the Symfony community on the web, and from the small number of Symfonyans in Australia - farwell and all the best!
In saying thanks to Francois, a few of us from Symfony nerds say farewell to Francois Zaninotto in our latest episode of the Instantiate Tech Podcast (Episode 4 - API’s). You can get it at the Instantiate Podcast website, subscribe to the RSS feed or via the iTunes Podcast Directory. Note: The farewell appears at the end of the Episode around 27:20.
Au revoir Francois!
29 Oct
Fabien Potencier has just published one of his presentations on how to “Decouple your code for reusability“. In this presentation he covers good techniques for decoupling your code as well as overviews Dependency Injection.
Dependency Injection is something that is quite prominent in Java frameworks, such as Spring. Martin Fowler covers the Dependency Injection pattern in quite some detail if you are interested.
Fabien summarizes it quite well for Symfony:
Dependency Injection is where components are given their dependencies through their constructors, methods, or directly into fields.
The Problem: Lets say you have a user class that reads the user Session from SessionStorage. We have to hard-code the SESSION_ID in the class:
1 2 3 4 5 6 7 8 9 10 | class User { protected $storage; function __construct() { $this->storage = new SessionStorage('SESSION_ID'); } function setLanguage($language) { $this->storage->set('language', $language); } // ... } |
Here we have the SESSION_ID hard-coded in the User class. What can we do to make this more modular? Well, you could use define() and define it as a global configuration variable, or you could pass it into the User class every time you instantiate it (eg $user = new User(”SESSION_ID”)). That would work well. But what would happen if we wanted to persist the Session to something else like the FileSystem? or the Database? What do we do then?
Instead of hard-coding the Storage dependency in the User class, we Inject the Storage dependency in the User object.
So we modify our User class so that the constructor takes storage as an argument:
1 2 3 4 5 6 7 8 | class User { protected $storage; function __construct($storage) { $this->storage = $storage; } } |
Then in our code, we can call it like this:
1 2 3 4 5 6 7 | //Use SessionStorage $storage = new SessionStorage('SESSION_ID'); $user = new User($storage); //Or we can use MySQLSessionStorage if we wanted to $storage = new MySQLSessionStorage('SESSION_ID'); $user = new User($storage); |
Fabien then goes on to further explain how you can abstract this a level further. Check out the full presentation on his site, its a great read.
20 Oct
A few of us here at Symfony Nerds get together to record a Tech podcast every now and then and talk about nerdy stuff. The podcast is called Instantiate Podcast.
This week we recorded our third episode where we talked about Enterprise Micro-blogging and web development frameworks. For anyone out there that is thinking of using Symfony, or looking at using a web development framework, checkout Episode 3. We talked about Frameworks and Symfony in some detail, here is what you will hear:
Have a listen to Instantiate Podcast - Episode 3 at the Instantiate Podcast website, or subscribe to the podcast in iTunes or RSS.
11 Oct
If you are looking for a way to distribute your Symfony application - either as a deployment package, to host on another server without Symfony libs, or giving it out as a product you could always use the Symfony sandbox to do so. However, this becomes hard to maintain when Symfony versions keep getting updated, and you have to keep your sandbox updated. So whats the best way to do this?
There is a great post over at the “Left on the Web” blog, that walks you through how to distribute your Symfony application enbedded within your project by using svn:externals. Be sure to check it out.
10 Oct
So where we are currently working, we have a back catalogue of Symfony 1.0 applications, and are beginning to roll out a few Symfony 1.1 apps to production, as well as a few other things floating around on other versions. As helpful as the compatability plugin is, it can’t magically make any 1.0 app run under 1.1, and we made the decision that we just couldn’t afford the time to re-write… So what’s the best way of running multiple versions of Symfony apps together on the one environment?
The first thing we thought of was just using PEAR to install multiple version in different directoris, but unfortunately it cannot handle installing more than one version, so that’s out.
You could grab a Symfony sandbox for each application, and if you only had one or two 1.0 apps this is probabaly quite a valid option, but if you have a few more, your code-base would get very large, very quickly, and you miss out on the benefit of re-using components across your apps from one location.
So what did we actually do? In the end, we installed multiple versions of Symfony via SVN, allowing the environment to operate much as anyone who installed Symfony with PEAR would be familiar with, allowing each Symfony application to reference the global Symfony install and libraries etc. The example below document how this was set up in Ubuntu (our favoured development VM), but shouldn’t be too different form other Unix environments.
Step 1 - Un-install Symfony via PEAR
If you have Symfony installed via PEAR, get rid of it, it will only confuse you with what we are about to do.
express@express-dev:~$ sudo pear uninstall symfony/symfony
uninstall ok: channel://pear.symfony-project.com/symfony-1.1.0
Step 2 - Setup a structure for Symfony
In our case, I still want to install symfony in /usr/share/php/symfony, so lets set that up:
express@express-dev:~$ cd /usr/share/php
express@express-dev:/usr/share/php$ sudo mkdir symfony
Step 3 - Checkout each Symfony version you need
Now lets use SVN checkout to grab each Symfony version we are after, lets put these in a different folder under the base Symfony directory. Note: If you are behind a proxy, change your SVN settings first to go through your proxy. To change your proxy settings:
express@express-dev:/usr/share/php/symfony$ sudo nano /etc/subversion/servers
Now lets checkout each symfony version:
express@express-dev:/usr/share/php$ cd symfony/
express@express-dev:/usr/share/php/symfony$ sudo svn co http://svn.symfony-project.com/branches/1.0 symfony10
...
express@express-dev:/usr/share/php/symfony$ sudo svn co http://svn.symfony-project.com/branches/1.1 symfony11
...
express@express-dev:/usr/share/php/symfony$ sudo svn co http://svn.symfony-project.com/branches/1.2 symfony12
...
We now have created three installations of Symfony.
Step 4 - Create symbolic links for each version
The next step is for us to create symlinks for each version of Symfony. Lets place these in the standard bin directory:
sudo ln -s /usr/share/php/symfony/symfony10/data/bin/symfony /usr/bin/symfony10
sudo ln -s /usr/share/php/symfony/symfony11/data/bin/symfony /usr/bin/symfony11
sudo ln -s /usr/share/php/symfony/symfony12/data/bin/symfony /usr/bin/symfony12
Now lets test the sym links:
express@express-dev:~$ symfony10 -V
symfony version 1.0.19-PRE
express@express-dev:~$ symfony11 -V
symfony version 1.1.5-DEV (/usr/share/php/symfony/symfony11/lib)
express@express-dev:~$ symfony12 -V
symfony version 1.2.0-DEV (/usr/share/php/symfony/symfony12/lib)
What next? - Creating a new project
So to create a new project, you will need to use the relevant Symfony command. For example, to create a Symfony 1.0 project:
sudo symfony10 init-project test1
or to create a Symfony 1.1 or Symfony 1.2 Project:
sudo symfony11 generate:project test11
sudo symfony12 generate:project test12
Once you create a new project, check in the project Config to ensure its picked up the right version. For Symfony 1.0:
express@express-dev:/usr/local/express/projects/$ sudo symfony10 init-project test10
express@express-dev:/usr/local/express/projects/$ cat config/config.php
// symfony directories $sf_symfony_lib_dir = '/usr/share/php/symfony/symfony10/lib'; $sf_symfony_data_dir = '/usr/share/php/symfony/symfony10/data';
for Symfony 1.1:
express@express-dev:/usr/local/express/projects/test$ cat config/ProjectConfiguration.class.php
require_once '/usr/share/php/symfony/symfony11/lib/autoload/sfCoreAutoload.class.php'; sfCoreAutoload::register(); class ProjectConfiguration extends sfProjectConfiguration { public function setup() { } }
and for Symfony 1.2, its the same, just make sure its including the right 1.2 files. Thats it! Hope this helps!
5 Oct
So work is beginning in the symfonynerds camp on a few 1.1 apps (just in time to have to migrate to 1.2 :p) and I thought it was time to start documenting some of the little tips we have for it.
Today I was fine tuning an app for UAT and wanted to configure the ‘years’ being listed in a sfWidgetFormDate Date Select.
In the first instance, it was for a ‘date of birth’ field, so I was looking for a range from about 1900 to 2000. The first thing that came to mind was the php function range() but as per this ticket raised (which I commented on as well as posting here) doesn’t work because the array keys increment from 0… So if you selected 1900, your year would be submitted as 0.
One way around it is to create a variable of your own with keys and values for the years, then pass it as the ‘year’ option, like the below.
$years = range(1920, 2000); //Creates array of years between 1920-2000 $years_list = array_combine($years, $years); //Creates new array where key and value are both values from $years list new sfWidgetFormDate(array('years' = $years_list))
Perhaps in the future Symfony could offer a way of automating this with ‘year_min’ and ‘year_max’ options for sfWidgetDormDate, or readers have a faster way of doing it.
1 Oct
If you are defining your schema.yml and have a field that is a decimal value, you will find you will need to somehow pass through the precision (maximum number of digits to the left of the point) and the scale (total number after the decimal point). The documentation for the syntax of this is quite poor.
For all those that want to know, in Symfony 1.0 this is how you would define a decimal:
my_decimal: { type: decimal, size: 8,3 }
For Symfony 1.1+, the Syntax is a bit different:
my_decimal:
type: decimal
size: 8
scale: 3
Where 8 is the precision and 3 is the scale. Hope this helps.
28 Sep
There is a great thread of posts in the Symfony Users Google Group about good practices on how to run multiple Symfony versions on the same machine. The different tips include:
Be sure to check it out
14 Sep
Here at Symfony Nerds, we were very upset to see that Symfony Camp wasnt held in Sydney, Australia
. So because we couldn’t go, we just hand to follow on closely from the land down under..
I recently stumbled across Dustin Whittle’s pressentation about lessons learned at Yahoo! with the Symfony PHP framework.
Worth a read if you get a chance.