Changeset 11662
- Timestamp:
- 09/18/08 20:36:11 (2 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
doc/branches/1.2/doctrine_book/en/01-Getting-Started.txt
r11624 r11662 4 4 >**NOTE** 5 5 >The symfony and Doctrine book does not explain in detail everything about Doctrine. It briefly touches on a few critical subjects that symfony utilizes the most. The Doctrine manual is still the best source of documentation for referencing everything that is Doctrine. It is recommended you read this book to get started and then utilize the Doctrine manual for referencing the specifics of using Doctrine. You can find the main Doctrine documentation [here](http://www.doctrine-project.org/documentation "Doctrine Documentation"). 6 7 ## What is Doctrine? 8 9 Doctrine is a PHP ORM (object relational mapper) for PHP 5.2.3+ that sits on top of a powerful PHP DBAL (database abstraction layer). One of its key features is the ability to optionally write database queries in an OO (object oriented) SQL-dialect called DQL inspired by Hibernates HQL. This provides developers with a powerful alternative to SQL that maintains a maximum of flexibility without requiring needless code duplication. 10 11 ## Enable Doctrine 6 12 7 13 In 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. … … 53 59 :migrate Migrates database to current/specified version (doctrine-migrate) 54 60 :rebuild-db Creates database for current model (doctrine-rebuild-db) 55 56 ## Import from Propel57 58 Doctrine has the ability to generate schema files from existing databases so all you need to do is make your configured Doctrine database have the schema of the database you want to import in to Doctrine. Run the following command to generate your yaml schema files from the existing database.59 60 $ ./symfony doctrine:build-schema frontend61 >> doctrine Generate YAML schema successfully from database62 63 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.64 65 CREATE TABLE user (id BIGINT AUTO_INCREMENT, username VARCHAR(255), password VARCHAR(255), PRIMARY KEY(id)) ENGINE = INNODB;66 67 The above mysql table would generate a yaml schema like the following in `config/doctrine/schema.yml`68 69 ---70 User:71 tableName: user72 columns:73 id:74 type: integer(8)75 primary: true76 autoincrement: true77 username: string(255)78 password: string(255)doc/branches/1.2/doctrine_book/en/02-Connections.txt
r11624 r11662 1 1 Chapter 2 - Connections 2 2 ======================= 3 4 >**TIP**5 >More can be read about connections in the Doctrine Manual [here](http://www.doctrine-project.org/documentation/manual/1_0?chapter=connection-management).6 3 7 4 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. … … 48 45 49 46 all: 50 d ictrube:47 doctrine: 51 48 class: sfDoctrineDatabase 52 49 param: … … 57 54 >**TIP** 58 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 57 ## Import from Propel 58 59 Doctrine has the ability to generate schema files from existing databases so all you need to do is make your configured Doctrine database have the schema of the database you want to import in to Doctrine. Run the following command to generate your yaml schema files from the existing database. 60 61 $ ./symfony doctrine:build-schema frontend 62 >> doctrine Generate YAML schema successfully from database 63 64 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. 65 66 CREATE TABLE user (id BIGINT AUTO_INCREMENT, username VARCHAR(255), password VARCHAR(255), PRIMARY KEY(id)) ENGINE = INNODB; 67 68 The above mysql table would generate a yaml schema like the following in `config/doctrine/schema.yml` 69 70 --- 71 User: 72 tableName: user 73 columns: 74 id: 75 type: integer(8) 76 primary: true 77 autoincrement: true 78 username: string(255) 79 password: string(255) 59 80 60 81 ## Multiple Connections … … 97 118 >**Note** 98 119 >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. 120 121 ## Connection Attributes 122 123 sfDoctrinePlugin allows you to specify connection attributes directly in the `config/databases.yml` file like the following. 124 125 all: 126 doctrine: 127 class: sfDoctrineDatabase 128 param: 129 dsn: mysql://root@localhost/dbname 130 attributes: 131 use_dql_callbacks: true 132 133 The attributes you specify here will be set on the Doctrine_Connection instances when the connection is created. 99 134 100 135 ## Build Everything doc/branches/1.2/doctrine_book/en/03-Configuration.txt
r11624 r11662 1 1 Chapter 3 - Configuration 2 2 ========================= 3 4 Doctrine 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.5 6 all:7 # all attributes below are set on the Doctrine_Manager instance8 attributes:9 # export sql (none, tables, constraints, all)10 export: all11 12 # enable doctrine side validation (true, false)13 validate: false14 15 # recursive merge functions from different directories/plugins16 recursive_merge_fixtures: true17 18 # enable quoting19 quote_identifier: false20 21 # enable autoloading of table class22 autoload_table_classes: true23 24 listeners: []25 record_listeners: []26 27 # Configuration for specific connection names28 # connections:29 # doctrine:30 # attributes:31 # export: all32 # listeners: []33 # record_listeners: []34 3 35 4 ## Attributes … … 37 6 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. Below explains how you can specify attributes at each level. Attributes can be specified globally, on each connection, or on each individual model. 38 7 8 In symfony you can control the Doctrine configuration in your `config/ProjectConfiguration.class.php` or `apps/frontend/config/frontendConfiguration.class.php` by creating a configureDoctrine() function. 9 39 10 ### Global Attributes 40 11 41 You can specify global attributes by editing `project/apps/frontend/config/doctrine.yml`. 42 43 all: 44 attributes: 45 use_dql_callbacks: true # Enable DQL callbacks globally 12 [php] 13 public function configureDoctrine() 14 { 15 $manager = Doctrine_Manager::getInstance(); 16 $manager->setAttribute('use_dql_callbacks', true); 17 } 46 18 47 19 ### Connection Attributes 48 20 49 You can specify connection attributes the same way you do global ones in `project/apps/frontend/config/doctrine.yml` with the following YAML. 50 51 all: 52 connections: 53 doctrine: 54 attributes: 55 export: tables # Only export tables when creating database from models 56 use_dql_callbacks: true # Enable DQL callbacks on this connection 21 [php] 22 public function configureDoctrine() 23 { 24 $conn = Doctrine_Manager::getInstance()->getConnection('connection_name'); 25 $conn->setAttribute('use_dql_callbacks', true); 26 } 57 27 58 28 ### Model Attributes doc/branches/1.2/doctrine_book/en/07-Migrations.txt
r11624 r11662 1 Chapter 6- Migrations1 Chapter 7 - Migrations 2 2 ====================== 3 3