forked from propelorm/PropelBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
210 lines (133 loc) · 6.07 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
Propel Bundle
=============
This is a (work in progress) implementation of Propel in Symfony2.
Currently supports:
* Generation of model classes based on an XML schema (not YAML) placed under `BundleName/Resources/*schema.xml`.
* Insertion of SQL statements.
* Runtime autoloading of Propel and generated classes.
* Propel runtime initialization through the XML configuration.
* Migrations [Propel 1.6](http://www.propelorm.org/wiki/Documentation/1.6/Migrations).
* Reverse engineering from [existing database](http://www.propelorm.org/wiki/Documentation/1.6/Existing-Database).
* Integration to the Symfony2 Profiler.
Installation
------------
* Clone this bundle in the `vendor/bundles/Propel` directory:
> git submodule add https://github.com/willdurand/PropelBundle.git vendor/bundles/Propel/PropelBundle
* Checkout Propel and Phing in the `vendor` directory:
> svn checkout http://svn.propelorm.org/branches/1.6 vendor/propel
> svn checkout http://phing.mirror.svn.symfony-project.com/tags/2.3.3 vendor/phing
* Instead of using svn, you can clone the unofficial Git repositories:
> git submodule add https://github.com/Xosofox/phing vendor/phing
> git submodule add https://github.com/Xosofox/propel1.6 vendor/propel
* Register this bundle in the `AppKernel` class:
public function registerBundles()
{
$bundles = array(
...
// PropelBundle
new Propel\PropelBundle\PropelBundle(),
// register your bundles
new Sensio\HelloBundle\HelloBundle(),
);
...
}
* Don't forget to register the PropelBundle namespace in `app/autoload.php`:
$loader->registerNamespaces(array(
...
'Propel' => __DIR__.'/../vendor/bundles',
));
Sample Configuration
--------------------
### Project configuration
# in app/config/config.yml
propel:
path: "%kernel.root_dir%/../vendor/propel"
phing_path: "%kernel.root_dir%/../vendor/phing"
# charset: "UTF8"
# logging: %kernel.debug%
# in app/config/config*.yml
propel:
dbal:
driver: mysql
user: root
password: null
dsn: mysql:host=localhost;dbname=test
options: {}
attributes: {}
# default_connection: default
# connections:
# default:
# driver: mysql
# user: root
# password: null
# dsn: mysql:host=localhost;dbname=test
# options: {}
# attributes: {}
### Sample Schema
Place the following schema in `src/Sensio/HelloBundle/Resources/config/schema.xml` :
<?xml version="1.0" encoding="UTF-8"?>
<database name="default" namespace="Sensio\HelloBundle\Model" defaultIdMethod="native">
<table name="book">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
<column name="title" type="varchar" primaryString="1" size="100" />
<column name="ISBN" type="varchar" size="20" />
<column name="author_id" type="integer" />
<foreign-key foreignTable="author">
<reference local="author_id" foreign="id" />
</foreign-key>
</table>
<table name="author">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
<column name="first_name" type="varchar" size="100" />
<column name="last_name" type="varchar" size="100" />
</table>
</database>
Commands
--------
### Build Process
Call the application console with the `propel:build` command:
> php app/console propel:build [--classes] [--sql] [--insert-sql]
### Insert SQL
Call the application console with the `propel:insert-sql` command:
> php app/console propel:insert-sql [--force]
Note that the `--force` option is needed to actually execute the SQL statements.
### Use The Model Classes
Use the Model classes as any other class in Symfony2. Just use the correct namespace, and Symfony2 will autoload them:
class HelloController extends Controller
{
public function indexAction($name)
{
$author = new \Sensio\HelloBundle\Model\Author();
$author->setFirstName($name);
$author->save();
return $this->render('HelloBundle:Hello:index.html.twig', array('name' => $name, 'author' => $author));
}
}
### Migrations
Generates SQL diff between the XML schemas and the current database structure:
> php app/console propel:migration:generate-diff
Executes the migrations:
> php app/console propel:migration:migrate
Executes the next migration up:
> php app/console propel:migration:migrate --up
Executes the previous migration down:
> php app/console propel:migration:migrate --down
Lists the migrations yet to be executed:
> php app/console propel:migration:status
### Working with existing databases
Run the following command to generate an XML schema from your `default` database:
> php app/console propel:reverse
You can define which connection to use:
> php app/console propel:reverse --connection=default
You can dump data from your database in XML to `app/propel/dump/xml/`:
> php app/console propel:data-dump [--connection[="..."]]
Once you ran `propel:data-dump` you can generate SQL statements from dumped data:
> php app/console propel:data-sql [--connection[="..."]]
SQL will be write in `app/propel/sql/`.
### Graphviz
You can generate **Graphviz** file for your project by using the following command line:
> php app/console propel:graphviz
It will write files in `app/propel/graph/`.
Known Problems
--------------
Your application must not be in a path including dots in directory names (i.e. '/Users/me/symfony/2.0/sandbox/' fails).