Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 119 lines (88 sloc) 2.698 kb
e7b7d77 @willdurand Rewrote the documentation
willdurand authored
1 The PropelParamConverter
2 ========================
3
fb1095c @jaugustin Update Resources/doc/param_converter.markdown
jaugustin authored
4 You can use the `PropelParamConverter` with the [SensioFrameworkExtraBundle](http://github.com/sensio/SensioFrameworkExtraBundle).
e7b7d77 @willdurand Rewrote the documentation
willdurand authored
5 You just need to put the right _Annotation_ on top of your controller:
6
7 ``` php
8 <?php
9
10 /**
11 * @ParamConverter("post", class="BlogBundle\Model\Post")
12 */
13 public function myAction(Post $post)
14 {
15 }
16 ```
17
18 Your request needs to have an `id` parameter or any field as parameter (slug, title, ...).
19
20 The _Annotation_ is optional if your parameter is typed you could only have this:
21
22 ``` php
23 <?php
24
25 public function myAction(Post $post)
26 {
27 }
28 ```
29
fb1095c @jaugustin Update Resources/doc/param_converter.markdown
jaugustin authored
30 **New** with last version of `SensioFrameworkExtraBundle`,
31 you can ommit the `class` parameter if your controller parameter is typed,
32 this is usefull when you need to set extra `options`.
33
34 ``` php
35 <?php
36 use BlogBundle\Model\Post;
37
38 /**
39 * @ParamConverter("post")
40 */
41 public function myAction(Post $post)
42 {
43 }
44 ```
45
e7b7d77 @willdurand Rewrote the documentation
willdurand authored
46 #### Exclude some parameters ####
47
48 You can exclude some attributes from being used by the converter:
49
50 If you have a route like `/my-route/{slug}/{name}/edit/{id}`
51 you can exclude `name` and `slug` by setting the option "exclude":
52
53 ``` php
54 <?php
55
56 /**
57 * @ParamConverter("post", class="BlogBundle\Model\Post", options={"exclude"={"name", "slug"}})
58 */
59 public function myAction(Post $post)
60 {
61 }
62 ```
63
b03f6a5 @jaugustin Add the mapping option for the PropelParamConverter,
jaugustin authored
64 #### Custom mapping ####
65
66 You can map route parameters directly to model column to be use for filtering.
67
68 If you have a route like `/my-route/{postUniqueName}/{AuthorId}`
69 Mapping option overwrite any other automatic mapping.
70
71 ``` php
72 <?php
73
74 /**
75 * @ParamConverter("post", class="BlogBundle\Model\Post", options={"mapping"={"postUniqueName":"name"}})
76 * @ParamConverter("author", class="BlogBundle\Model\Author", options={"mapping"={"AuthorId":"id"}})
77 */
78 public function myAction(Post $post, $author)
79 {
80 }
81 ```
e7b7d77 @willdurand Rewrote the documentation
willdurand authored
82
1b5b182 @jaugustin [WIP] rebase, refactor code, add tests, add doc
jaugustin authored
83 #### Hydrate related object ####
84
85 You could hydrate related object with the "with" option:
86
87 ``` php
88 <?php
89
90 /**
91 * @ParamConverter("post", class="BlogBundle\Model\Post", options={"with"={"Comments"}})
92 */
93 public function myAction(Post $post)
94 {
95 }
96 ```
97
98 You can set multiple with ```"with"={"Comments", "Author", "RelatedPosts"}```.
99
100 The default join is an "inner join" but you can configure it to be a left join, right join or inner join :
101
102 ``` php
103 <?php
104
105 /**
106 * @ParamConverter("post", class="BlogBundle\Model\Post", options={"with"={ {"Comments", "left join" } }})
107 */
108 public function myAction(Post $post)
109 {
110 }
111 ```
112 Accepted parmeters for join :
113
aa884ec @jaugustin PropelParamConverter fix doc markdown render
jaugustin authored
114 * left, LEFT, left join, LEFT JOIN, left_join, LEFT_JOIN
115 * right, RIGHT, right join, RIGHT JOIN, right_join, RIGHT_JOIN
116 * inner, INNER, inner join, INNER JOIN, inner_join, INNER_JOIN
1b5b182 @jaugustin [WIP] rebase, refactor code, add tests, add doc
jaugustin authored
117
e7b7d77 @willdurand Rewrote the documentation
willdurand authored
118 [Back to index](index.markdown)
Something went wrong with that request. Please try again.