3

I have been creating a table from mysql result , but its printing the html markup only and says controller must return a response . what may be the reason ?

LogicException: The controller must return a response (

(5 rows)group_nameparent_nameEditDeleteSelect itemsL2V9http://192.168.1.236/mailusers/usergroup/edit/6>edithttp://192.168.1.236/mailusers/usergroup/delete/6>delete

L3v3http://192.168.1.236/mailusers/usergroup/edit/7>edithttp://192.168.1.236/mailusers/usergroup/delete/7>deleteAdminsV6http://192.168.1.236/mailusers/usergroup/edit/8>edithttp://192.168.1.236/mailusers/usergroup/delete/8>deleteL4Vodafonehttp://192.168.1.236/mailusers/usergroup/edit/9>edithttp://192.168.1.236/mailusers/usergroup/delete/9>deleteVCNONetworkhttp://192.168.1.236/mailusers/usergroup/edit/12>edithttp://192.168.1.236/mailusers/usergroup/delete/12>delete
given). in Symfony\Component\HttpKernel\HttpKernel->handleRaw() (line 157 of vendor/symfony/http-kernel/HttpKernel.php).

1 Answer 1

11

The error message is not pointing in the right direction. It should say:

"The controller must return a render array"

For example the most basic one:

return [
  '#markup' => '<p>This is html markup</p>',
];

Usually the render array is more complex, for example to build a table, see https://www.codimth.com/blog/web/drupal/render-table-drupal-8

The error message is raised by Symfony, and from the stand point of Symfony this is correct. A controller must provide a response, but Drupal has extended the response handling to look for render arrays, that are then used to generate a response with the rendered html. If you don't provide a render array, then there is no response and then this error message will come up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.