Skip to content

Commit d401b9e

Browse files
committed
How to configure Doctrine using yaml
I rewrote the solution proposed by mahok in http://stackoverflow.com/a/14988359/842697
1 parent b77fc8b commit d401b9e

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

Resources/doc/index.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,14 @@ and place your `User` class in it.
115115
> to call parent::__construct(), as the base User class depends on
116116
> this to initialize some fields.
117117
118-
**a) Doctrine ORM User class**
118+
#### a) Doctrine ORM User class
119119

120120
If you're persisting your users via the Doctrine ORM, then your `User` class
121121
should live in the `Entity` namespace of your bundle and look like this to
122122
start:
123123

124+
##### Annotations
125+
124126
``` php
125127
<?php
126128
// src/Acme/UserBundle/Entity/User.php
@@ -155,7 +157,48 @@ class User extends BaseUser
155157

156158
> `User` is a reserved keyword in SQL so you cannot use it as table name.
157159
158-
**b) MongoDB User class**
160+
##### yaml
161+
162+
If you use yml to configure Doctrine you must add two files. The Entity and the orm.yml:
163+
164+
```php
165+
<?php
166+
// src/Acme/UserBundle/Entity/User.php
167+
168+
namespace Acme\UserBundle\Entity;
169+
170+
use Doctrine\ORM\Mapping as ORM;
171+
use FOS\UserBundle\Entity\User as BaseUser;
172+
173+
/**
174+
* User
175+
*/
176+
class User extends BaseUser {
177+
/**
178+
* @var integer
179+
*/
180+
protected $id;
181+
182+
public function __construct()
183+
{
184+
parent::__construct();
185+
// your own logic
186+
}
187+
}
188+
```
189+
```yaml
190+
# src/Acme/UserBundle/Resources/config/doctrine/User.orm.yml
191+
Acme\UserBundle\Entity\User:
192+
type: entity
193+
table: fos_user
194+
id:
195+
id:
196+
type: integer
197+
strategy: { generator: "AUTO" }
198+
lifecycleCallbacks: { }
199+
```
200+
201+
#### b) MongoDB User class
159202
160203
If you're persisting your users via the Doctrine MongoDB ODM, then your `User`
161204
class should live in the `Document` namespace of your bundle and look like
@@ -188,7 +231,7 @@ class User extends BaseUser
188231
}
189232
```
190233

191-
**c) CouchDB User class**
234+
#### c) CouchDB User class
192235

193236
If you're persisting your users via the Doctrine CouchDB ODM, then your `User`
194237
class should live in the `Document` namespace of your bundle and look like

0 commit comments

Comments
 (0)