public function nodeList() {
$header = [
'Nid',
'Title',
];
$query = \Drupal::database()->select('node', 'n');
$query->fields('n', ['nid']);
$pager = $query->extend('Drupal\Core\Database\Query\PagerSelectExtender')->limit(10);
$results = $pager->execute()->fetchAll();
foreach ($results as $key => $result) {
$node = Node::load($result->nid);
$row = [];
$row = [
'nid' => $node->id(),
'title' => $node->getTitle(),
];
$rows[] = $row;
}
$build['table_data'] = [
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
];
// Finally add the pager.
$build['pager'] = array(
'#type' => 'pager'
);
return $build;
}
$header = [
'Nid',
'Title',
];
$query = \Drupal::database()->select('node', 'n');
$query->fields('n', ['nid']);
$pager = $query->extend('Drupal\Core\Database\Query\PagerSelectExtender')->limit(10);
$results = $pager->execute()->fetchAll();
foreach ($results as $key => $result) {
$node = Node::load($result->nid);
$row = [];
$row = [
'nid' => $node->id(),
'title' => $node->getTitle(),
];
$rows[] = $row;
}
$build['table_data'] = [
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
];
// Finally add the pager.
$build['pager'] = array(
'#type' => 'pager'
);
return $build;
}
Comments
Post a Comment