@@ -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.ini `` file:
33
33
34
34
.. code-block :: ini
@@ -42,20 +42,17 @@ information. By convention, this information is usually configured in an
42
42
database_password = password
43
43
database_charset = UTF8
44
44
45
- .. note ::
46
-
47
- Defining the configuration via ``parameters.ini `` is just a convention. The
48
- parameters defined in that file are referenced by the main configuration
49
- file when setting up Propel:
45
+ These parameters defined in ``parameters.ini `` can now be included in the
46
+ configuration file (``config.yml ``):
50
47
51
- .. code-block :: yaml
48
+ .. code-block :: yaml
52
49
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%"
50
+ propel :
51
+ dbal :
52
+ driver : " %database_driver%"
53
+ user : " %database_user%"
54
+ password : " %database_password%"
55
+ dsn : " %database_driver%:host=%database_host%;dbname=%database_name%;charset=%database_charset%"
59
56
60
57
Now that Propel knows about your database, Symfony2 can create the database for
61
58
you:
@@ -88,12 +85,28 @@ of your ``AcmeStoreBundle``:
88
85
.. code-block :: xml
89
86
90
87
<?xml version =" 1.0" encoding =" UTF-8" ?>
91
- <database name =" default" namespace =" Acme\StoreBundle\Model" defaultIdMethod =" native" >
88
+ <database name =" default"
89
+ namespace =" Acme\StoreBundle\Model"
90
+ defaultIdMethod =" native"
91
+ >
92
92
<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" />
93
+ <column name =" id"
94
+ type =" integer"
95
+ required =" true"
96
+ primaryKey =" true"
97
+ autoIncrement =" true"
98
+ />
99
+ <column name =" name"
100
+ type =" varchar"
101
+ primaryString =" true"
102
+ size =" 100"
103
+ />
104
+ <column name =" price"
105
+ type =" decimal"
106
+ />
107
+ <column name =" description"
108
+ type =" longvarchar"
109
+ />
97
110
</table >
98
111
</database >
99
112
@@ -217,15 +230,15 @@ have a route that maps a product id to an update action in a controller::
217
230
218
231
Updating an object involves just three steps:
219
232
220
- #. fetching the object from Propel;
221
- #. modifying the object;
222
- #. saving it.
233
+ #. fetching the object from Propel (line 6 - 13) ;
234
+ #. modifying the object (line 15) ;
235
+ #. saving it (line 16) .
223
236
224
237
Deleting an Object
225
238
~~~~~~~~~~~~~~~~~~
226
239
227
- Deleting an object is very similar, but requires a call to the `` delete() ``
228
- method on the object::
240
+ Deleting an object is very similar to updating , but requires a call to the
241
+ `` delete() `` method on the object::
229
242
230
243
$product->delete();
231
244
0 commit comments