/** * Call HTMLTable with column definitions only including some columns. * * @return string the HTML code. */ function testWriteTableSubset() { $tbl = new HTMLTable(); /* * Table definitions matching the testdata table in the testdata.sqlite table. */ $colDefsSubset = [['displayName' => 'Name', 'propertyName' => 'name'], ['displayName' => 'Age', 'propertyName' => 'age']]; $tbl->setColumns($colDefsSubset); $out = "<h3>Output some columns</h3>\n" . "<p>Print only the name and age columns</p>\n"; $res = readTestdata(); $out .= $tbl->create($res); return $out; }
/** * Anax pagecontroller to demonstrate usage of HTMLTable with Anax */ // Get environment & autoloader and the $app-object. require __DIR__ . '/config_with_app.php'; use Bjurnemark\HTMLTable\CHTMLTable as HTMLTable; /** * Serialized objects corresponding to data in sqlite db */ $sObjects = ['O:8:"stdClass":4:{s:2:"id";s:1:"1";s:4:"name";s:4:"Adam";s:3:"age";s:2:"10";s:7:"updated";s:10:"2016-02-10";}', 'O:8:"stdClass":4:{s:2:"id";s:1:"2";s:4:"name";s:6:"Bertil";s:3:"age";s:2:"20";s:7:"updated";s:10:"2016-02-09";}', 'O:8:"stdClass":4:{s:2:"id";s:1:"3";s:4:"name";s:5:"Cesar";s:3:"age";s:2:"30";s:7:"updated";s:10:"2016-02-08";}', 'O:8:"stdClass":4:{s:2:"id";s:1:"4";s:4:"name";s:5:"David";s:3:"age";s:2:"41";s:7:"updated";s:10:"2016-02-07";}', 'O:8:"stdClass":4:{s:2:"id";s:1:"5";s:4:"name";s:4:"Erik";s:3:"age";N;s:7:"updated";s:10:"2016-02-06";}', 'O:8:"stdClass":4:{s:2:"id";s:1:"6";s:4:"name";s:0:"";s:3:"age";s:2:"60";s:7:"updated";N;}']; // Unserialize the objects $objects = array(); foreach ($sObjects as $str) { $objects[] = unserialize($str); } /* * Table definitions matching the testdata. */ $colDefs = [['displayName' => 'ID', 'propertyName' => 'id'], ['displayName' => 'Name', 'propertyName' => 'name'], ['displayName' => 'Age', 'propertyName' => 'age'], ['displayName' => 'Last updated', 'propertyName' => 'updated']]; // Create the HTMLTable object $tbl = new HTMLTable(); // Set the column definitions $tbl->setColumns($colDefs); $content = "<h2>Demo HTMLTable</h2>\n"; // Create the HTML-code for the table $content .= $tbl->create($objects); // Prepare the page content $app->theme->setVariable('title', "HTMLTable demo")->setVariable('main', $content); // Render the response using theme engine. $app->theme->render();