Development

Changeset 11597

You must first sign up to be able to contribute.

Changeset 11597

Show
Ignore:
Timestamp:
09/16/08 17:27:33 (2 months ago)
Author:
Jonathan.Wage
Message:

[1.2] Continuing writing of symfony and Doctrine book.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • doc/branches/1.2/doctrine_book/en/01-Getting-Started.txt

    r11589 r11597  
    1 # Getting Started 
     1Chapter 1 - Getting Started 
     2=========================== 
    23 
    34In order to begin using Doctrine you must first enable it in your application with the following command. It will automatically make some configuration changes and create directories that Doctrine require. 
     
    1213 
    1314## Available Tasks 
     15 
     16Below is the complete list of tasks available with the sfDoctrinePlugin. It offers all the same functionality as propel plus much more. 
    1417 
    1518    $ ./symfony list doctrine 
     
    5558    >> doctrine  Generate YAML schema successfully from database 
    5659 
    57 Now have a look in config/doctrine/schema.yml and you will see the yaml for the database. In this example we have a user table. 
     60Now have a look in `config/doctrine/schema.yml` and you will see the yaml for the database. In this example we have a user table. 
    5861 
    5962    CREATE TABLE user (id BIGINT AUTO_INCREMENT, username VARCHAR(255), password VARCHAR(255), PRIMARY KEY(id)) ENGINE = INNODB; 
    6063 
    61 The above mysql table would generate a yaml schema like the following. 
     64The above mysql table would generate a yaml schema like the following in `config/doctrine/schema.yml` 
    6265 
    6366    --- 
  • doc/branches/1.2/doctrine_book/en/02-Connections.txt

    r11589 r11597  
    1 # Connections 
     1Chapter 2 - Connections 
     2======================= 
    23 
    3 In this chapter we'll explain some things about Doctrine connections. How to configure them, how to use multiple of them and bind models to connections, how to create and drop your databases and other connection related activities. 
     4In this chapter we'll explain some things about Doctrine connections, how to configure them, how to use multiple of them and bind models to connections, how to create and drop your databases and other connection related activities. 
    45 
    5 The default databases.yml should look something like this
     6The default `config/databases.yml` should look like the following. The only difference here is that it is sfDoctrineDatabase instead of sfPropelDatabase and the connection name is doctrine instead of propel
    67 
    78    all: 
     
    2526* SQLite — SQLite Functions (PDO_SQLITE) 
    2627 
     28## DSN 
    2729 
    28 ## DSN 
     30Doctrine offers two ways of specifying your DSN information. You can use the portable Doctrine style DSN or use the native PDO style DSN. 
    2931 
    3032### Doctrine Style 
     
    5052          password:     password 
    5153 
     54>**TIP** 
     55>Using the PDO style syntax offers more flexibility and ability to specify non standard information about your connection to PDO. For example, when specifying non standard unix_socket paths or ports to use when connecting, specifying it in PDO syntax is more flexible. 
     56 
    5257## Multiple Connections 
    5358 
    54 Doctrine offers the ability to have multiple connection instances and bind models to connections so all model operations are executed on a specific connection. Below is an example config/databases.yml with multiple databases. 
     59Doctrine offers the ability to have multiple connections. You can easily bind models to connections so that queries are executed on the appropriate dbms. Below is an example `config/databases.yml` with multiple databases. 
    5560 
    5661    all: 
     
    6469          dsn:          mysql://root@localhost/client 
    6570 
    66 Now say we have a User model which you want to bind to the master database. You can simply do this directly in the definition of the model like below. Place the following YAML code in config/doctrine/schema.yml 
     71Now say we have a User model which you want to bind to the master database. You can simply do this directly in the definition of the model like below. Place the following YAML code in `config/doctrine/schema.yml` 
    6772 
    6873    Client: 
     
    7378        password: string(255) 
    7479 
    75 Now each Client can have Stores but they are stored in a separate database from the Users. 
     80Now each Client can have Stores but they are saved in a separate database from the Users. 
    7681 
    7782    Store: 
     
    8893 
    8994>**Note** 
    90 >Because the tables are in separate databases the data can only be lazily loaded. Doctrine does not currently support generating sql for joining tables across databases. Also notice the export attributes being set to tables so Doctrine does not try and export any foreign keys to the dbms. 
     95>Because the tables are in separate databases the data can only be lazily loaded. Doctrine does not currently support generating sql for joining tables across databases. Also, notice the export attribute being set to tables. This tells Doctrine to only export the create table statement and not any foreign keys. 
    9196 
    9297## Build Everything 
    9398 
    94 Now that we have our connections and schema defined we can build everything with the following command. 
     99Now that we have our connections and schema defined we can build everything with the following command. This command will drop your database if it already exists, re-create it, build your models from `config/doctrine/*.yml`, create the tables in your databases and load your data fixtures from `data/fixtures/*.yml`. 
    95100 
    96101    ./symfony doctrine-build-all-reload frontend 
     
    107112>**Note** 
    108113>You can take a look at the models which were generated from your YAML schema files in lib/model/doctrine and lib/model/doctrine/generated. The files in the generated folder are re-written each time you build your models whereas the ones below the generated directory are not. You may customize your models by editing the classes in lib/model/doctrine. 
     114 
     115Here is what the `lib/model/doctrine/generated/BaseClient.class.php` should look like. 
     116 
     117    [php] 
     118    /** 
     119     * This class has been auto-generated by the Doctrine ORM Framework 
     120     */ 
     121    abstract class BaseClient extends sfDoctrineRecord 
     122    { 
     123      public function setTableDefinition() 
     124      { 
     125        $this->setTableName('client'); 
     126        $this->hasColumn('name', 'string', 255, array('type' => 'string', 'length' => '255')); 
     127        $this->hasColumn('username', 'string', 255, array('type' => 'string', 'length' => '255')); 
     128        $this->hasColumn('password', 'string', 255, array('type' => 'string', 'length' => '255')); 
     129      } 
     130 
     131      public function setUp() 
     132      { 
     133        $this->hasMany('Store as Stores', array('local' => 'id', 
     134                                                'foreign' => 'client_id')); 
     135      } 
     136    } 
     137 
     138>**TIP** 
     139>It is common practice to run the `./symfony doctrine:build-all-reload-test` command when developing. This will rebuild your entire environment and run the full test suite. This is a good command to run before committing new code to ensure no new regressions have occurred. 
  • doc/branches/1.2/doctrine_book/en/03-Configuration.txt

    r11589 r11597  
    1 # Configuration 
     1Chapter 3 - Configuration 
     2========================= 
    23 
    3 Doctrine controls most configuration from the project/apps/frontend/config/doctrine.yml which should have been copied for you with the `$ ./symfony doctrine:enable frontend` command. Below is the sample configuration that comes bundled with Doctrine. 
     4Doctrine controls most configuration from the `project/apps/frontend/config/doctrine.yml` which was copied for you with the `$ ./symfony doctrine:enable frontend` command. Below is the sample configuration that comes bundled with Doctrine. 
    45 
    56    all: 
     
    3435## Attributes 
    3536 
    36 Doctrine controls features and settings with attributes. The attributes can be defined at different levels of a hierarchy. Some attributes can be specified at all levels and others cannot. This chapter explains how you can specify attributes at each level. Attributes can be specified globally, on each connection, or on each individual model. 
     37Doctrine controls features and settings with attributes. The attributes can be defined at different levels of a hierarchy. Some attributes can be specified at all levels and others cannot. Below explains how you can specify attributes at each level. Attributes can be specified globally, on each connection, or on each individual model. 
    3738 
    3839### Global Attributes 
    3940 
    40 You can specify global attributes by editing project/apps/frontend/config/doctrine.yml
     41You can specify global attributes by editing `project/apps/frontend/config/doctrine.yml`
    4142 
    4243    all: 
     
    4647### Connection Attributes 
    4748 
    48 You can specify connection attributes the same way you do global ones in project/apps/frontend/config/doctrine.yml with the following YAML. 
     49You can specify connection attributes the same way you do global ones in `project/apps/frontend/config/doctrine.yml` with the following YAML. 
    4950 
    5051    all: