Tables of records via ItemList
- Home
- Core helpers
- Tables of records via ItemList
The helper to create a table of records is called Itemlist
, and it provides the UI which is seen on the contents view of most admin controllers. For example:
An Itemlist to generate a table like the one above, for use outside of the normal admin controller space, would look something like the following:
src/modules/Users/Controllers/UserController.php
<?php // TODO: use statements, namespace etc. here class UserController extends Controller { function user_list() { $view = new View('modules/Users/user_list'); $list = new Itemlist(); // Note that this is the same definition used for main_columns // in a ManagedAdminController $list->main_columns = [ 'First name' => 'first_name', 'Last name' => 'last_name', 'Email' => 'last_name', ]; $q = "SELECT id, first_name, last_name, email FROM ~users WHERE active = 1"; $list->items = Pdb::query($q, [], 'pdo'); // N.B. these checkboxes would still need to be programmed // to *do* something $list->checkboxes = true; $view->user_list = $list->render(); // TODO: skin etc. here instead of just rendering echo $view->render(); } }