Last updated September 15, 2013. Created by mparker17 on August 15, 2013.
Edited by webchick, rabellamy, Crell. Log in to edit this page.

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'

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.