@@ -56,6 +56,11 @@ public function indexAction()
56
56
* Creates a new Post entity.
57
57
*
58
58
* @Route("/new", name="admin_post_new")
59
+ * @Method({"GET", "POST"})
60
+ *
61
+ * NOTE: the Method annotation is optional, but it's a recommended practice
62
+ * to constraint the HTTP methods each controller responds to (by default
63
+ * it responds to all methods).
59
64
*/
60
65
public function newAction (Request $ request )
61
66
{
@@ -84,12 +89,12 @@ public function newAction(Request $request)
84
89
/**
85
90
* Finds and displays a Post entity.
86
91
*
87
- * @Route("/{id}", name="admin_post_show")
92
+ * @Route("/{id}", requirements={"id" = "\d+"}, name="admin_post_show")
88
93
* @Method("GET")
89
94
* @Security("post.isAuthor(user)")
90
95
*
91
- * NOTE: You can also centralize security logic by using a "voter"
92
- * http://symfony.com/doc/current/cookbook/security/voters_data_permission.html
96
+ * NOTE: You can also centralize security logic by using a "voter"
97
+ * See http://symfony.com/doc/current/cookbook/security/voters_data_permission.html
93
98
*/
94
99
public function showAction (Post $ post )
95
100
{
@@ -104,7 +109,8 @@ public function showAction(Post $post)
104
109
/**
105
110
* Displays a form to edit an existing Post entity.
106
111
*
107
- * @Route("/{id}/edit", name="admin_post_edit")
112
+ * @Route("/{id}/edit", requirements={"id" = "\d+"}, name="admin_post_edit")
113
+ * @Method({"GET", "POST"})
108
114
* @Security("post.isAuthor(user)")
109
115
*/
110
116
public function editAction (Post $ post , Request $ request )
@@ -136,6 +142,10 @@ public function editAction(Post $post, Request $request)
136
142
* @Route("/{id}", name="admin_post_delete")
137
143
* @Method("DELETE")
138
144
* @Security("post.isAuthor(user)")
145
+ *
146
+ * The Security annotation value is an expression (if it evaluates to false,
147
+ * the authorization mechanism will prevent the user accessing this resource).
148
+ * The isAuthor() method is defined in the AppBundle\Entity\Post entity.
139
149
*/
140
150
public function deleteAction (Request $ request , Post $ post )
141
151
{
@@ -155,6 +165,12 @@ public function deleteAction(Request $request, Post $post)
155
165
/**
156
166
* Creates a form to delete a Post entity by id.
157
167
*
168
+ * This is necessary because browsers don't support HTTP methods different
169
+ * from GET and POST. Since the controller that removes the blog posts expects
170
+ * a DELETE method, the trick is to create a simple form that *fakes* the
171
+ * HTTP DELETE method.
172
+ * See http://symfony.com/doc/current/cookbook/routing/method_parameters.html.
173
+ *
158
174
* @param Post $post The post object
159
175
*
160
176
* @return \Symfony\Component\Form\Form The form
0 commit comments