@@ -7,7 +7,7 @@ Databases and Propel
7
7
One of the most common and challenging tasks for any application
8
8
involves persisting and reading information to and from a database. Symfony2
9
9
does not come integrated with any ORMs but the Propel integration is easy.
10
- To get started , read `Working With Symfony2 `_.
10
+ To install Propel , read `Working With Symfony2 `_ on the Propel documentation .
11
11
12
12
A Simple Example: A Product
13
13
---------------------------
@@ -28,7 +28,7 @@ Configuring the Database
28
28
~~~~~~~~~~~~~~~~~~~~~~~~
29
29
30
30
Before you can start, you'll need to configure your database connection
31
- information. By convention, this information is usually configured in an
31
+ information. By convention, this information is usually configured in an
32
32
``app/config/parameters.yml `` file:
33
33
34
34
.. code-block :: yaml
@@ -48,14 +48,17 @@ information. By convention, this information is usually configured in an
48
48
parameters defined in that file are referenced by the main configuration
49
49
file when setting up Propel:
50
50
51
- .. code-block :: yaml
51
+ These parameters defined in ``parameters.yml `` can now be included in the
52
+ configuration file (``config.yml ``):
52
53
53
- propel :
54
- dbal :
55
- driver : " %database_driver%"
56
- user : " %database_user%"
57
- password : " %database_password%"
58
- dsn : " %database_driver%:host=%database_host%;dbname=%database_name%;charset=%database_charset%"
54
+ .. code-block :: yaml
55
+
56
+ propel :
57
+ dbal :
58
+ driver : " %database_driver%"
59
+ user : " %database_user%"
60
+ password : " %database_password%"
61
+ dsn : " %database_driver%:host=%database_host%;dbname=%database_name%;charset=%database_charset%"
59
62
60
63
Now that Propel knows about your database, Symfony2 can create the database for
61
64
you:
@@ -88,12 +91,28 @@ of your ``AcmeStoreBundle``:
88
91
.. code-block :: xml
89
92
90
93
<?xml version =" 1.0" encoding =" UTF-8" ?>
91
- <database name =" default" namespace =" Acme\StoreBundle\Model" defaultIdMethod =" native" >
94
+ <database name =" default"
95
+ namespace =" Acme\StoreBundle\Model"
96
+ defaultIdMethod =" native"
97
+ >
92
98
<table name =" product" >
93
- <column name =" id" type =" integer" required =" true" primaryKey =" true" autoIncrement =" true" />
94
- <column name =" name" type =" varchar" primaryString =" true" size =" 100" />
95
- <column name =" price" type =" decimal" />
96
- <column name =" description" type =" longvarchar" />
99
+ <column name =" id"
100
+ type =" integer"
101
+ required =" true"
102
+ primaryKey =" true"
103
+ autoIncrement =" true"
104
+ />
105
+ <column name =" name"
106
+ type =" varchar"
107
+ primaryString =" true"
108
+ size =" 100"
109
+ />
110
+ <column name =" price"
111
+ type =" decimal"
112
+ />
113
+ <column name =" description"
114
+ type =" longvarchar"
115
+ />
97
116
</table >
98
117
</database >
99
118
@@ -217,15 +236,15 @@ have a route that maps a product id to an update action in a controller::
217
236
218
237
Updating an object involves just three steps:
219
238
220
- #. fetching the object from Propel;
221
- #. modifying the object;
222
- #. saving it.
239
+ #. fetching the object from Propel (line 6 - 13) ;
240
+ #. modifying the object (line 15) ;
241
+ #. saving it (line 16) .
223
242
224
243
Deleting an Object
225
244
~~~~~~~~~~~~~~~~~~
226
245
227
- Deleting an object is very similar, but requires a call to the `` delete() ``
228
- method on the object::
246
+ Deleting an object is very similar to updating , but requires a call to the
247
+ `` delete() `` method on the object::
229
248
230
249
$product->delete();
231
250
0 commit comments