Skip to content

Commit 350743c

Browse files
committed
Merge pull request #870 from hussfelt/master
Adding information about pluralization into documentation
2 parents b5c77e0 + 1157fbc commit 350743c

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

Resources/doc/5-automatic-route-generation_single-restful-controller.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,5 +283,49 @@ use FOS\RestBundle\Controller\Annotations\Route;
283283
}
284284
```
285285

286+
### Changing pluralization in generated routes
287+
288+
If you want to change pluralization in generated routes, you can do this by replacing
289+
"fos_rest.inflector.doctrine" service with your own implementation.
290+
Create a new class that implements "FOS\RestBundle\Util\Inflector\InflectorInterface".
291+
292+
The example below will remove pluralization by implementing the interface and returning the "$word"
293+
instead of executing method ```Inflector::pluralize($word);```
294+
295+
**Example class implementing InflectorInterface**
296+
```php
297+
<?php
298+
namespace Acme\HelloBundle\Util\Inflector;
299+
300+
use FOS\RestBundle\Util\Inflector\InflectorInterface;
301+
302+
/**
303+
* Inflector class
304+
*
305+
*/
306+
class NoopInflector implements InflectorInterface
307+
{
308+
public function pluralize($word)
309+
{
310+
// Don't pluralize
311+
return $word;
312+
}
313+
}
314+
```
315+
316+
**Define your service in config.yml**
317+
```
318+
services:
319+
acme.hellobundle.util.inflector:
320+
class: Acme\HelloBundle\Util\NoopInflector
321+
```
322+
323+
**Tell fos_rest to use your own service as inflector, also in config.yml**
324+
```
325+
fos_rest:
326+
service:
327+
inflector: acme.hellobundle.util.inflector
328+
```
329+
286330
## That was it!
287331
[Return to the index](index.md) or continue reading about [Automatic route generation: multiple RESTful controllers](6-automatic-route-generation_multiple-restful-controllers.md).

0 commit comments

Comments
 (0)