Skip to content
Newer
Older
100644 228 lines (168 sloc) 11.2 KB
8e6722e @willdurand Updated README
willdurand authored
1 sfPropelORMPlugin
2 =================
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
3
8e6722e @willdurand Updated README
willdurand authored
4 Replaces symfony's core Propel plugin by the latest version of Propel, in branch 1.6.
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
5
8e6722e @willdurand Updated README
willdurand authored
6 ## Installation
7
8 ### The Git way
9
10 Clone the plugin from Github:
11
12 git clone git://github.com/propelorm/sfPropelORMPlugin.git plugins/sfPropelORMPlugin
13 cd plugins/sfPropelORMPlugin
d2372a0 @willdurand Fixed git typo
willdurand authored
14 git submodule update --init
8e6722e @willdurand Updated README
willdurand authored
15
16 If you use Git as a VCS for your project, it should be better to add the plugin as a submodule:
17
18 git submodule add git://github.com/propelorm/sfPropelORMPlugin.git plugins/sfPropelORMPlugin
19 git submodule init --update --recursive
20
21 As both Phing and Propel libraries are bundled with the plugin, you have to initialize submodules for the plugin.
22
23 ### The SVN way
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
24
25 Install the plugin via the subversion repository:
26
8e6722e @willdurand Updated README
willdurand authored
27 svn checkout http://svn.github.com/propelorm/sfPropelORMPlugin.git plugins/sfPropelORMPlugin
28
29 Install `Phing` and `Propel`:
30
a3edbd5 @lucasaba Ads cleanliness to the code
lucasaba authored
31 cd lib/vendor
8e6722e @willdurand Updated README
willdurand authored
32 svn checkout http://phing.mirror.svn.symfony-project.com/tags/2.3.3/classes/phing phing
33 svn checkout http://svn.github.com/propelorm/Propel.git propel
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
34
a3edbd5 @lucasaba Ads cleanliness to the code
lucasaba authored
35 Optional: add a reference to the propel and phing folders in the test project:
36
37 ``` php
38 // plugins/sfPropelORMPlugin/test/functional/fixtures/config/ProjectConfiguration.class.php
39
40 class ProjectConfiguration extends sfProjectConfiguration
41 {
42 public function setup()
43 {
44 $this->enablePlugins(array('sfPropelORMPlugin'));
45 $this->setPluginPath('sfPropelORMPlugin', realpath(dirname(__FILE__) . '/../../../..'));
46 sfConfig::set('sf_phing_path', SF_DIR.'/../phing');
47 sfConfig::set('sf_propel_path', SF_DIR.'/../propel');
48 }
49 ```
50
8e6722e @willdurand Updated README
willdurand authored
51 ### Final step
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
52
8e6722e @willdurand Updated README
willdurand authored
53 Disable the core Propel plugin and enable the `sfPropelORMPlugin` instead:
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
54
8e6722e @willdurand Updated README
willdurand authored
55 ``` php
56 // config/ProjectConfiguration.class.php
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
57
8e6722e @willdurand Updated README
willdurand authored
58 class ProjectConfiguration extends sfProjectConfiguration
59 {
4878b50 @willdurand Fixed README
willdurand authored
60 public function setup()
61 {
8e6722e @willdurand Updated README
willdurand authored
62 $this->enablePlugins('sfPropelORMPlugin');
a3edbd5 @lucasaba Ads cleanliness to the code
lucasaba authored
63 // If you're following the SVN way, uncomment the following lines
64 //sfConfig::set('sf_phing_path', sfConfig::get('sf_root_dir').'/lib/vendor/phing');
65 //sfConfig::set('sf_propel_path', sfConfig::get('sf_root_dir').'/lib/vendor/propel');
4878b50 @willdurand Fixed README
willdurand authored
66 }
8e6722e @willdurand Updated README
willdurand authored
67 }
68 ```
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
69
4878b50 @willdurand Fixed README
willdurand authored
70 Right after the installation of the plugin, you should update plugin assets:
71
72 php symfony plugin:publish-assets
73
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
74 Change the path of the symfony behaviors in the `config/propel.ini` file of your project:
75
8e6722e @willdurand Updated README
willdurand authored
76 ``` ini
77 // config/propel.ini
78
79 propel.behavior.symfony.class = plugins.sfPropelORMPlugin.lib.behavior.SfPropelBehaviorSymfony
80 propel.behavior.symfony_i18n.class = plugins.sfPropelORMPlugin.lib.behavior.SfPropelBehaviorI18n
81 propel.behavior.symfony_i18n_translation.class = plugins.sfPropelORMPlugin.lib.behavior.SfPropelBehaviorI18nTranslation
82 propel.behavior.symfony_behaviors.class = plugins.sfPropelORMPlugin.lib.behavior.SfPropelBehaviorSymfonyBehaviors
83 propel.behavior.symfony_timestampable.class = plugins.sfPropelORMPlugin.lib.behavior.SfPropelBehaviorTimestampable
84 ```
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
85
86 (Re)Build the model:
87
8e6722e @willdurand Updated README
willdurand authored
88 php symfony propel:build --all-classes
89
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
90
8e6722e @willdurand Updated README
willdurand authored
91 ## What's New In Propel 1.6
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
92
8e6722e @willdurand Updated README
willdurand authored
93 Propel 1.6 is a **backwards compatible** evolution of Propel 1.4 (the version bundled with symfony 1.3 and 1.4), which adds some very interesting features. Among these features, you will find the **new Propel Query API**, which is essentially a Criteria on steroids:
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
94
8e6722e @willdurand Updated README
willdurand authored
95 ``` php
96 // find the 10 latest books published by authror 'Leo'
97 $books = BookQuery::create()
98 ->useAuthorQuery()
99 ->filterByFirstName('Leo')
100 ->endUse()
101 ->orderByPublishedAt('desc')
102 ->limit(10)
103 ->find($con);
104 ```
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
105
8e6722e @willdurand Updated README
willdurand authored
106 Propel 1.6 also supports **many-to-many relationships**, **collections**, **on-demand hydration**, **new core behaviors** (see below), better Oracle support, and is now licensed under the MIT license.
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
107
108
8e6722e @willdurand Updated README
willdurand authored
109 ## Core Propel Behaviors
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
110
8e6722e @willdurand Updated README
willdurand authored
111 Propel 1.6 bundles most common behaviors in a new, robust buildtime implementation. These core behaviors provide faster runtime execution and the ability to modify the data model:
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
112
8e6722e @willdurand Updated README
willdurand authored
113 - [timestampable](http://www.propelorm.org/wiki/Documentation/1.6/Behaviors/timestampable)
114 - [sluggable](http://www.propelorm.org/wiki/Documentation/1.6/Behaviors/sluggable)
115 - [soft_delete]([http://www.propelorm.org/wiki/Documentation/1.6/Behaviors/soft_delete)
116 - [nested_set](http://www.propelorm.org/wiki/Documentation/1.6/Behaviors/nested_set)
117 - [sortable](http://www.propelorm.org/wiki/Documentation/1.6/Behaviors/sortable)
118 - [concrete_inheritance](http://www.propelorm.org/wiki/Documentation/1.6/Inheritance#ConcreteTableInheritance)
119 - [query_cache](http://www.propelorm.org/wiki/Documentation/1.6/Behaviors/query_cache)
9d248d4 @GromNaN typo
GromNaN authored
120 - [alternative_coding_standards](http://www.propelorm.org/wiki/Documentation/1.6/Behaviors/alternative_coding_standards)
8e6722e @willdurand Updated README
willdurand authored
121 - [auto_add_pk](http://www.propelorm.org/wiki/Documentation/1.6/Behaviors/auto_add_pk)
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
122
8e6722e @willdurand Updated README
willdurand authored
123 `sfPropelORMPlugin` allows you to register core propel behaviors right from your `schema.yml`. For instance, to create a tree structure from a `Section` model:
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
124
8e6722e @willdurand Updated README
willdurand authored
125 ``` yaml
126 propel:
127 section:
128 _attributes: { phpName: Section }
129 _propel_behaviors:
130 - nested_set
131 id: ~
132 title: { type: varchar(100), required: true primaryString: true }
133 ```
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
134
8e6722e @willdurand Updated README
willdurand authored
135 **Tip**: Check the [`doc/schema.md`](https://raw.github.com/propelorm/sfPropelORMPlugin/master/doc/schema.md) file in this plugin source code for a complete reference of the YAML schema format.
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
136
8e6722e @willdurand Updated README
willdurand authored
137 You can also register a behavior for all your models right in the `propel.ini` configuration file. `sfPropelORMPlugin` already enables the `symfony` and `symfony_i18n` behaviors to support symfony's behavior system and model localization features, but you can easily add your owns:
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
138
8e6722e @willdurand Updated README
willdurand authored
139 ``` ini
140 propel.behavior.default = symfony,symfony_i18n,alternative_coding_standards,auto_add_pk
141 ```
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
142
8e6722e @willdurand Updated README
willdurand authored
143 ## Admin Generator Extensions
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
144
8e6722e @willdurand Updated README
willdurand authored
145 The plugin comes bundled with a new admin generator theme named 'admin15'. This theme is backwards compatible with sfPropelPlugin's admin generator theme, and provides additional features based on the new Propel 1.6 query objects:
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
146
147 ### List view enhancements
148
149 - **Easy related objects hydration**: You don't need to write custom `doSelectJoinXXX()` methods to hydrate related objects. The `with` setting is much more poxwerful that the previous `peer_method` and `peer_count_method` settings, and much easier to use.
150 - **Custom query methods**: You can refine the query executed to display the list view by by setting the `query_methods` parameter. This allows to hydrate an additional column wit hno additional query, or to pre-filter the list to hide rows that the user shouldn't see.
151 - **All columns are sortable**: Virtual columns and foreign key columns are now sortable in the list view. You'll need to set the sort method to use for that, but it's a one-liner. No more lists with column headers that can't be clicked for sorting!
152 - **Easy links to filtered lists**: A link to a fitlered list view is very easy to write with the new theme. Just add GET parameter, the same way you used to do with the admin generator in symfony 1.2, and it works
153 - **Links to another admin module**: To make a foreign key column link to the edit view of the related object in another module, you no longer need to create a partial. Just define the `link_module` setting in the foreign key field configuration, and you're good to go:
154 - **Easy custom filters**: Adding custom filters becomes very easy once you can take advantage of the generated Propel query classes. This allows your, for instance, to setup a full-text search input in two minutes, replacing many text filters by a single one for better usability.
155
156 ### Filter and Edit forms enhancement
157
158 - **YAML widget customization**: The `generator.yml` format was extended to allow widget and validator customization directly in YAML, without the need to edit a form object. You can also safely omit a field from a `display` list in a form definition, without any risk to loose data.
159 - **Plain text field**: If you want to display some data in a form without allowing the user to edit it, use the `type: plain` attribute, just like in the old days of symfony 1.2. This is very useful for columns managed by the model, like `created_at` and `updated_at` columns.
160
8e6722e @willdurand Updated README
willdurand authored
161 The new options for the `admin15` generator theme are fully documented, and illustrated by real life examples, in the [`doc/admin_generator.md`](https://raw.github.com/propelorm/sfPropelORMPlugin/master/doc/admin_generator.md) file in this plugin source code.
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
162
8e6722e @willdurand Updated README
willdurand authored
163 ## Form Subframework Modifications
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
164
0ba5f54 Removed trailing spaces
rozwell authored
165 - **Updated `sfWidgetFormPropelChoice` widget**: The widget now uses the new Query API. You can customize the list of choices more easily by executing custom query methods, using the new `query_methods` option.
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
166 - **Updated Propel validators**: Both the `sfValidatorPropelChoice` and the `sfValidatorPropelUnique` were updated to use the new PropelQuery objects, and to accept a `query_methods` option similar to the one of `sfWidgetFormPropelChoice`.
167 - **Plain text widget and validator**: This new widget allows a field to be displayed in a form, without letting the use change it.
168 - **Easy Relation Embed**: Editing related objects together with the main objects (e.g., editing `Comments` in a `Post` form) is a piece of cake. The new `sfFormPropel::embedRelation()` method does all the work to fetch related objects, build the forms for each of them, and embed the related object forms into the main form. Embdeded relation forms allow to **edit**, **add**, and **delete** a related objects with no additional code.
169
8e6722e @willdurand Updated README
willdurand authored
170 ``` php
171 class ArticleForm extends BaseArticleForm
172 {
76a8cf1 @willdurand Fixed indentation in README
willdurand authored
173 public function configure()
174 {
8e6722e @willdurand Updated README
willdurand authored
175 $this->embedRelation('Book');
76a8cf1 @willdurand Fixed indentation in README
willdurand authored
176 }
8e6722e @willdurand Updated README
willdurand authored
177 }
178 ```
179
180 The Propel widgets, validators, and form classes are fully documented in the [`doc/form.md`](https://raw.github.com/propelorm/sfPropelORMPlugin/master/doc/form.md) file in this plugin source code.
181
182 ## Routing Modifications
183
184 The plugin offer two new routing classes, `sfPropelORMRoute` and `sfPropelORMRouteCollection`. These classes are used by default in the models build with the propel admin generator. They behave just like the previous `sfPropelRoute` class - except they don't use the `methods` option anymore. Instead, use the `query_methods` option to execute a list of arbitrary query methods when calling `getObject()` and `getObjects()`.
185
186 ``` yaml
187 author:
188 class: sfPropelORMRouteCollection
189 options:
190 model: author
191 module: author
192 prefix_path: /author
193 column: id
194 query_methods:
195 object: [filterByIsPublished]
196 list: [filterByIsPublished, orderByLastName]
197 with_wildcard_routes: true
198 ```
a0ecb20 @fzaninotto [1.6] Markdown is more natural and easier to read than RST, reverting…
fzaninotto authored
199
09f08af query methods:
rozwell authored
200 Array of additional parameters are also possible for `query_methods`:
201
8e6722e @willdurand Updated README
willdurand authored
202 ``` yaml
203 author:
204 class: sfPropelORMRouteCollection
205 options:
206 model: author
207 module: author
208 prefix_path: /author
209 column: id
210 query_methods:
211 object:
212 filterByIsPublished: [false]
213 list:
214 filterByIsPublished: []
215 orderBy: [LastName]
216 with_wildcard_routes: true
217 ```
218
219 `sfPropelORMRoute` also makes your code a little easier to read in the action. Instead of calling `getObject()`, you can actually call a getter using the class name of the object's route:
220
221 ``` php
222 public function executeShow(sfWebRequest $request)
223 {
224 // using sfPropelORMRoute with 'Author' as model
225 $this->author = $this->getRoute()->getAuthor();
226 }
227 ```
Something went wrong with that request. Please try again.