You are here

public function DbtngExampleController::entryList in Examples for Developers 8

Same name and namespace in other branches
  1. 3.x modules/dbtng_example/src/Controller/DbtngExampleController.php \Drupal\dbtng_example\Controller\DbtngExampleController::entryList()

Render a list of entries in the database.

1 string reference to 'DbtngExampleController::entryList'
dbtng_example.routing.yml in dbtng_example/dbtng_example.routing.yml
dbtng_example/dbtng_example.routing.yml

File

dbtng_example/src/Controller/DbtngExampleController.php, line 45

Class

DbtngExampleController
Controller for DBTNG Example.

Namespace

Drupal\dbtng_example\Controller

Code

public function entryList() {
  $content = [];
  $content['message'] = [
    '#markup' => $this
      ->t('Generate a list of all entries in the database. There is no filter in the query.'),
  ];
  $rows = [];
  $headers = [
    $this
      ->t('Id'),
    $this
      ->t('uid'),
    $this
      ->t('Name'),
    $this
      ->t('Surname'),
    $this
      ->t('Age'),
  ];
  $entries = $this->repository
    ->load();
  foreach ($entries as $entry) {

    // Sanitize each entry.
    $rows[] = array_map('Drupal\\Component\\Utility\\Html::escape', (array) $entry);
  }
  $content['table'] = [
    '#type' => 'table',
    '#header' => $headers,
    '#rows' => $rows,
    '#empty' => $this
      ->t('No entries available.'),
  ];

  // Don't cache this page.
  $content['#cache']['max-age'] = 0;
  return $content;
}