After reading the Symfony book it was not clear to me how to deal with servers in the config setting. Say that you are creating a site on your local computer and then want to deploy it to your server. Some variables might be different, like in my case the image directory.
Symfony nicely support setting variables for development environments, but I found no such functionality for different servers. In the meanwhile I’ve created a simple filter setup which deals with the problem very nicely.
First set your config values in the frontend/config/app.yml:
all: server: 'local' local: imagedir: 'http://comments/comment/images/' production: imagedir: 'http://www.mellowmorning.com/symfony-examples/images/'
Next create a filter in lib/filters/setconfFilter.class.php:
class setconfFilter extends sfFilter { public function execute($filterChain) { // Execute this filter only once if ($this->isFirstCall()) { define('SERVER', sfConfig::get('app_server')); define('IMAGE_DIR', sfConfig::get('app_'.SERVER.'_imagedir')); } // Execute next filter $filterChain->execute(); } }
Now to tie our little labor together set in frontend/config/filters.yml between security and cache:
setconf: ~
class: setconfFilter
Here you now have your own server dependant config settings, just use IMAGE_DIR in your template and it will refer to the correct location. If you are really lazy and do not want to change your app.yml every time you sync with production, we could automate that in the filter as well. Simple write something like this in the filter to define the SERVER constant:
define('SERVER', ($_SERVER['SERVER_NAME']=='comments')?'local':'production');
and remove the definition of the server from the app.yml.
Read more: About filters
Read more: the Symfony configuration system
PS. Also have a look at some of the great cheatsheets out there, from the Symfony wiki:
Admin generator cheat sheet
Directory structure and CLI
View
View: Partials, Components, Slots and Component Slots
Form Helpers
Javascript and Ajax Helpers
Server Validation
Model
Model: Schema
Lime Unit & Functional Testing
ORM Diagram