Skip to main content
Adding more references
Source Link
squall3d
  • 449
  • 3
  • 5

From the error, I assume your code is in a controller? In that case, take note that you should return a render array or an object inheriting the Response class, not HTML.

In your case, just do:

return $items_array;

instead of

return render($items_array);

But wait!

The table render array should be constructed this way:

$items_array = array(
  '#theme' => 'table',
  '#header' => $header, 
  '#rows' => $rows,
); 

For a reference of what you can pass in, check out https://api.drupal.org/api/drupal/core%21modules%21system%21templates%21table.html.twig/8.1.x

Other notes

The way you are querying data is not wrong per se but definitely not the "Drupal way". To perform queries using Drupal's DBAL, check out https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Database!database.api.php/group/database/8.2.x

From the error, I assume your code is in a controller? In that case, take note that you should return a render array or an object inheriting the Response class, not HTML.

In your case, just do:

return $items_array;

instead of

return render($items_array);

But wait!

The table render array should be constructed this way:

$items_array = array(
  '#theme' => 'table',
  '#header' => $header, 
  '#rows' => $rows,
); 

From the error, I assume your code is in a controller? In that case, take note that you should return a render array or an object inheriting the Response class, not HTML.

In your case, just do:

return $items_array;

instead of

return render($items_array);

But wait!

The table render array should be constructed this way:

$items_array = array(
  '#theme' => 'table',
  '#header' => $header, 
  '#rows' => $rows,
); 

For a reference of what you can pass in, check out https://api.drupal.org/api/drupal/core%21modules%21system%21templates%21table.html.twig/8.1.x

Other notes

The way you are querying data is not wrong per se but definitely not the "Drupal way". To perform queries using Drupal's DBAL, check out https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Database!database.api.php/group/database/8.2.x

Source Link
squall3d
  • 449
  • 3
  • 5

From the error, I assume your code is in a controller? In that case, take note that you should return a render array or an object inheriting the Response class, not HTML.

In your case, just do:

return $items_array;

instead of

return render($items_array);

But wait!

The table render array should be constructed this way:

$items_array = array(
  '#theme' => 'table',
  '#header' => $header, 
  '#rows' => $rows,
);