You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Resources/doc/5-automatic-route-generation_single-restful-controller.md
+44Lines changed: 44 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -283,5 +283,49 @@ use FOS\RestBundle\Controller\Annotations\Route;
283
283
}
284
284
```
285
285
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
+
286
330
## That was it!
287
331
[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