Symfony /w Doctrine Setup Guide
Abstract
A quick cheat guide for setting up symfony (/w doctrine). This assumes you already have your html being served from respective dir.
Setup Symfony Environment
cd /path/to/where/you/want/symfony
wget http://www.symfony-project.org/get/symfony-1.2.9.tgz
tar -xvpf symfony-1.2.9.tgz
ln -s /path/to/symfony/symfony-1.2.9 symfony
Generate Symfony Project
cd /path/to/html
php /path/to/symfony/data/bin/symfony generate:project <project_name>
Generate Symfony Project App
–escaping-strategy prevents XSS (cross site scripting) attacks, and –csrf-secret prevents CSRF (Cross Site Request Forgery) attacks. CSRF uses <super_secret_salt> to hash out values on all your form pages as hidden elements so we enforce that any requests made to form actions orgininated from our site, and not someone elses.
php symfony generate:app --escaping-strategy=on --csrf-secret=<super_secret_salt> <app_name>
Enable Doctrine for Symfony
vi config/ProjectConfiguration.class.php
$this->enablePlugins(array('sfDoctrinePlugin'));
OR
$this->enableAllPluginsExcept(array('sfPropelPlugin', 'sfCompat10Plugin'));
Clear Cache
php symfony cc
Publish Assets
This step lets symfony know that you have some plugins you are ready to use.
php symfony plugin:publish-assets
Remove Propel Artifacts
rm web/sfPropelPlugin
rm config/propel.ini config/schema.yml config/databases.yml
Add Doctrine Artifacts
mkdir config/doctrine
Create databases.yml File
php symfony configure:database --name=doctrine --class=sfDoctrineDatabase "mysql:host=<host_name>;dbname=<db_name>" <db_user> <db_password>
Secure databases.yml File
chmod 600 config/databases.yml
Build Schema
Building schema will create a config/doctrine/schema.yml file. It is basically a text version of your database schema. You can edit as you see fit, but for most users it isn’t necessary, but you should at least check it out to see what’s going on.
php symfony doctrine:build-schema
vi config/doctrine/schema.yml
Doctrine Options Configuration (optional)
You can over-ride doctrine model generation options by create a configureDoctrin() method in config/ProjectConfiguration.class.php file. These settings allow you to control elements of the model creation, for example; I dont like creating the extraneous ‘*Tables’ model files so I set ‘generateTableClasses’ to false, like so:
vi config/ProjectConfiguration.class.php
public function configureDoctrine()
{
$options = array(
'generateTableClasses' => FALSE
);
sfConfig::set('doctrine_model_builder_options', $options);
}
You can find more information and configuration options on the Symfony Website under Doctrine Configuration.
Symfony Model Generation
The ‘model’ refers to the files that allow access to data stored within your database. These files are created automatically based on your config/doctrine/schema.yml file and placed in /lib/model/doctrine/
php symfony doctrine:build-model
Setup Symfony Module
Only use this if you DO NOT PLAN on using Symfony’s Admin Generator, otherwise you may run into issues. In order to start editing actions and template scripts, you need to run the following command in /path/to/project/apps/<app_name>:
php symfony generate:module <app_name> <module_name>
Setup Symfony default css
This will give access to the symfony default css so that web toolbar and default symfony pages look nice.
cd web
ln -s /path/to/symfony/symfony/data/web/sf sf
Enable Login Authentication (optional)
This will protect your app by forcing a user to login to view any app files. You will have to add code to handle login authentication and is covered in my sfGuardDoctrine plugin post.
vi apps/<app_name>/config/security.yml
Before
default: is_secure: off
After
default: is_secure: on
Allow Access to Dev Controller
If you are developing on an remote environment and you need access to the dev controller (<app>_dev.php), you will have to add your IP address to <app>_dev.php, as it defaults to localhost.
EOF
If you followed each of the above steps, you have successfully created a symfony project, app, module. You can access your project using the following links:
App: http://yourdomain.com/<app_name>_dev.php (should see success project landing page)
Module: http://yourdomain.com/<app_name>_dev.php/<module_name> (should see success module landing page)
Forms, Actions, etc will be discussed in other setup guides.
