HANDS ON DOCTRINE :: An Interactive One Hour Tutorial on Doctrine's ORM for PHP

This is a hands on tutorial that I have build in order to leave my developers' team starting to learn Doctrine by they own in a real world example.

This has only been tested on the following linux environment:

- Apache/2.2.4 (Ubuntu) PHP/5.2.3-1ubuntu6.3
- Mysql 5.0.45
- Doctrine 0.10.3 and 0.10.4

We supose to have a database for create a News System with multilanguage based on the following schema:
- All news are setup on CONT_NEWS
- title and body are setup on TRANSL_NEWS as per language translation

At the end we will have a view that incorporates the content of CONT_NEWS with the content of TRANSL_NEWS based on the join: where id=id_news with the content per language in different rows:

3. SQL code
Here we can see the SQL code for creating the 4 tables and 1 view on MySQL. news.sql

4. Doctrine Import Sample
Here we can see how we create the Models in Doctrine from our existing database doctrine_import.php
The resulting output will be a folder named news with all the generated models:

Warning: If you use 0.10.4, you must read this issue for correcting the generated models. Also you must add 'primary' => true to id_lang and id_news for correcting the generated BaseViewNews.php

5. Doctrine Querying Samples (Insert, Update, Delete, Select, etc.)
Here we have all the samples for learning Doctrine in a hands on real sample in just one our.

The included 11 steps are:
// 01 Connection and model loading
// 02 Insert three rows into SYS_LANG
// 03 Retrieve rows from SYS_LANG
// 04 Insert language definitions in TRANS_LANG
// 05 Retrieve rows from TRANS_LANG
// 06 Add a row in CONT_NEWS and each language content as three rows in TRANSL_NEWS
// 07 Retrieve rows from VIEW_NEWS
// 08 Test Delete a row in TRANSL_NEWS
// 09 Re-add again en_US
// 10 Update en_US
// 11 Retrieve Partial Data
// 12 Raw Sql

The resulting output should be something like doctrine_learning.output.html

6. Beyond Here
Suggestions, corrections, are wellcome.
Don't forget to read the official documentation http://www.phpdoctrine.org/documentation
and col.laborate in the user http://groups.google.com/group/doctrine-user and developers http://groups.google.com/group/doctrine-dev groups.

2008-04-07 jaume@teixi.net on Teixi.net