1 dbtng_example.module | dbtng_example_list() |
Render a list of entries in the database.
Related topics
File
- modules/
examples/ dbtng_example/ dbtng_example.module, line 364 - This is an example outlining how a module can make use of the DBTNG database API in Backdrop.
Code
function dbtng_example_list() {
$output = '';
// Get all entries in the dbtng_example table.
if ($entries = dbtng_example_entry_load()) {
$rows = array();
foreach ($entries as $entry) {
// Sanitize the data before handing it off to the theme layer.
$rows[] = array_map('check_plain', (array) $entry);
}
// Make a table for them.
$header = array(t('Id'), t('uid'), t('Name'), t('Surname'), t('Age'));
$output .= theme('table', array('header' => $header, 'rows' => $rows));
}
else {
backdrop_set_message(t('No entries have been added yet.'));
}
return $output;
}