<?php
/* project: Array grid, file: arraygrid.php */
//Include pclib framework
require 'pclib/pclib.php';
//Create pclib application
$app = new PCApp('demo');
$datasource = 'pdo_mysql://user:password@localhost/test';
$app->db = new PCDb($datasource);
//the format of dataarray is the same as what is returned by db
//$dataArray = array($row_1,$row_2,...);
//each $row_n is assoc.array containing pairs fieldname: value
$dataArray = $app->db->selectAll('PRODUCTS');
//show how $dataArray looks like
if ($app->action == 'datasource') {
var_dump(array_slice($dataArray, 0, 3));
return;
}
//Initialize grid template, set grid query and write grid out
$grid = new PCGrid('tpl/arraygrid.tpl');
//If user click on filter link, apply filter
if ($app->action == 'filter')
$grid->filter['productVendor'] = 'Unimax*';
//we use setArray() instead of setQuery()
$grid->setArray($dataArray);
print $grid;
?>
Elapsed time: 22.3 ms