WSCCI Conversion Guide - Best practices
Last updated on
15 October 2016
Separate controller objects for different return types
All controller methods in the same class should be intended for use with the same route key i.e.: they should all be intended for use with _content or _controller, but not a mix of both. For example,
# Routes that return content.
module.some_route:
defaults:
_content: '\Drupal\my_module\Controller\ContentController::someRoute'
module.other_route:
defaults:
_content: '\Drupal\my_module\Controller\ContentController::otherRoute'
# Routes that return something else.
module.some_ajax_route:
defaults:
_controller: '\Drupal\my_module\Controller\AjaxController::someAjaxRoute'
Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion