Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 119 lines (91 sloc) 4.206 kb
1bfb208 Mariano Iglesias README updates
authored
1 li3\_doctrine2 offers integration between [the most RAD PHP framework] [lithium]
b7bce75 Mariano Iglesias Adding README
authored
2 and possibly the best PHP 5.3 ORM out there: [Doctrine2] [doctrine2]
3
4 # License #
5
1bfb208 Mariano Iglesias README updates
authored
6 li3\_doctrine2 is released under the [BSD License] [license].
b7bce75 Mariano Iglesias Adding README
authored
7
8 # Installation #
9
1bfb208 Mariano Iglesias README updates
authored
10 It is recommended that you install li3\_doctrine2 as a GIT submodule, in order
b7bce75 Mariano Iglesias Adding README
authored
11 to keep up with the latest upgrades. To do so, switch to the core directory
12 holding your lithium application, and do:
13
14 ```bash
540750d Mariano Iglesias Fixing repo URL
authored
15 $ git submodule add https://github.com/mariano/li3_doctrine2.git app/libraries/li3_doctrine2
b7bce75 Mariano Iglesias Adding README
authored
16 $ cd app/libraries/li3_doctrine2 && git submodule update --init
17 $ cd _source/doctrine2 && git submodule update --init
18 ```
19
1bfb208 Mariano Iglesias README updates
authored
20 # Usage #
21
b9bef23 Mariano Iglesias README updates
authored
22 ## Adding the li3\_doctrine2 library ##
1bfb208 Mariano Iglesias README updates
authored
23
24 Once you have downloaded li3_doctrine2 and placed it in your `app/libraries`,
25 or your main `libraries` folder, you need to enable it by placing the following
26 at the end of your `app/config/bootstrap/libraries.php` file:
27
28 ```php
29 Libraries::add('li3_doctrine2');
30 ```
31
32 ## Defining a connection ##
33
b9bef23 Mariano Iglesias README updates
authored
34 Setting up a connection with li3\_doctrine2 is easy. All you need to do is
35 add the following to your `app/config/bootstrap/connections.php` file (make
36 sure to edit the settings to match your host, without altering the `type`
37 setting):
38
39 ```php
40 Connections::add('default', array(
41 'type' => 'Doctrine',
42 'driver' => 'pdo_mysql',
43 'host' => 'localhost',
44 'user' => 'root',
45 'password' => 'password',
46 'dbname' => 'kontractor'
47 ));
48 ```
1bfb208 Mariano Iglesias README updates
authored
49
50 ## Creating models ##
51
52 When looking to create your doctrine models, you have two choices: you can
53 have them follow your custom class hierarchy (or not at all), or you could
54 have them extend from the `BaseEntity` class provided by this library. The
b9bef23 Mariano Iglesias README updates
authored
55 advantage of choosing the later is that your models will have lithium's
56 validation support, and can be better integrated with the custom adapters (such
57 as for session management, or for authorization) provided by this library.
58
59 Let us create a `User` model. Following doctrine's [basic mapping guide]
60 [doctrine-mapping-guide] we'll use annotations to define the properties (notice
61 how we are choosing to extend this model from `BaseEntity`):
62
63 ```php
64 ```
1bfb208 Mariano Iglesias README updates
authored
65
66 # Integrating Doctrine libraries #
67
68 In this section I'll cover some of the doctrine extension libraries out there,
69 and how to integrate them with li3_doctrine2.
70
71 ## DoctrineExtensions ##
b7bce75 Mariano Iglesias Adding README
authored
72
73 If there is one tool I would recommend you checkout for your Doctrine models,
e811e60 Mariano Iglesias Fixing link reference in README
authored
74 that would be [DoctrineExtensions] [DoctrineExtensions]. It provides with a set
b7bce75 Mariano Iglesias Adding README
authored
75 of behavioral extensions to the Doctrine core that will simplify your
76 development.
77
78 To use DoctrineExtensions, you should first add it as GIT submodule. To do so,
79 switch to the core directory holding your lithium application, and do:
80
81 ```bash
82 $ git submodule add https://github.com/l3pp4rd/DoctrineExtensions.git app/libraries/_source/DoctrineExtensions
83 ```
84
85 Next you would use your connection configuration (in `app/config/connections.php`)
86 to configure Doctrine with your desired behaviors. For example, if you wish
87 to use Timestampable and Sluggable, you would first add the library in
88 `app/config/libraries.php`:
89
90 ```php
91 Libraries::add('Gedmo', array(
1bfb208 Mariano Iglesias README updates
authored
92 'path' => LITHIUM_APP_PATH . '/libraries/_source/DoctrineExtensions/lib/Gedmo'
b7bce75 Mariano Iglesias Adding README
authored
93 ));
94 ```
95
a165763 Mariano Iglesias Making the creation of entity manager filterable
authored
96 And then you would filter the `createEntityManager` method in the `Doctrine`
97 datasource to add the behaviors. Edit your `app/config/connections.php` file
98 and add the following right below the connection definition:
b7bce75 Mariano Iglesias Adding README
authored
99
100 ```php
a165763 Mariano Iglesias Making the creation of entity manager filterable
authored
101 Connections::get('default')->applyFilter('createEntityManager',
102 function($self, $params, $chain) {
103 $params['eventManager']->addEventSubscriber(
104 new \Gedmo\Timestampable\TimestampableListener()
b7bce75 Mariano Iglesias Adding README
authored
105 );
a165763 Mariano Iglesias Making the creation of entity manager filterable
authored
106 $params['eventManager']->addEventSubscriber(
107 new \Gedmo\Sluggable\SluggableListener()
108 );
109 return $chain->next($self, $params, $chain);
b7bce75 Mariano Iglesias Adding README
authored
110 }
a165763 Mariano Iglesias Making the creation of entity manager filterable
authored
111 );
b7bce75 Mariano Iglesias Adding README
authored
112 ```
113
114 [lithium]: http://lithify.me
115 [doctrine2]: http://www.doctrine-project.org
116 [license]: http://www.opensource.org/licenses/bsd-license.php
117 [DoctrineExtensions]: https://github.com/l3pp4rd/DoctrineExtensions
b9bef23 Mariano Iglesias README updates
authored
118 [doctrine-mapping-guide]: http://www.doctrine-project.org/docs/orm/2.1/en/reference/basic-mapping.html
Something went wrong with that request. Please try again.