Navigation Menu

Skip to content

Commit

Permalink
added some basic docs for FriendsOfSymfony#269
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 committed Sep 3, 2012
1 parent 8a8e29b commit be6a0da
Showing 1 changed file with 67 additions and 1 deletion.
Expand Up @@ -38,7 +38,7 @@ you can use ``name_prefix`` on an import only when the file is imported itself w

```php
<?php
class UsersController extends Controller
class UsersController
{
public function optionsUsersAction()
{} // "options_users" [OPTIONS] /users
Expand Down Expand Up @@ -111,6 +111,72 @@ class UsersController extends Controller
That's all. All your resource (``UsersController``) actions will get mapped to the proper routes
as shown in the comments in the above example. Here are a few things to note:

#### Implicit resource name definition

Its possible to omit the ``User`` part of the method names since optionally FOSRestBundle
can determine the resource based on the Controller name. However for this to work its important
to use singular names in the Controller. However by omitting the resource name from the methods
``getUserAction`` and ``getUsersAction`` there would be an overlap of method names there is a
special convention to call the methods ``getAction`` and ``cgetAction``, where the ``c`` standard
for collection. So the following would work as well.

```
<?php
class UserController
{
..
public function cgetAction()
{} // "get_users" [GET] /users
public function newAction()
{} // "new_users" [GET] /users/new
public function getAction($slug)
{} // "get_user" [GET] /users/{slug}
..
public function getCommentsAction($slug)
{} // "get_user_comments" [GET] /users/{slug}/comments
..
}
```

Finally its possible to override the resource name derived from the Controller name via the
``@RouteResource`` annotation:


```
<?php
use FOS\RestBundle\Controller\Annotations\RouteResource;
/**
* @RouteResource("User")
*/
class FooController
{
..
public function cgetAction()
{} // "get_users" [GET] /users
public function newAction()
{} // "new_users" [GET] /users/new
public function getAction($slug)
{} // "get_user" [GET] /users/{slug}
..
public function getCommentsAction($slug)
{} // "get_user_comments" [GET] /users/{slug}/comments
..
}
```

### REST Actions

There are 5 actions that have special meaning in regards to REST and have the following behavior:
Expand Down

0 comments on commit be6a0da

Please sign in to comment.