<?php
/* project: Basic grid, file: basicgrid.php */
/* We want remember sorting and filtering. It will be stored in session. */
session_start();
//Include pclib framework
require 'pclib/pclib.php';
//Create pclib application
$app = new PCApp('demo');
$datasource = 'pdo_mysql://user:password@localhost/test';
//Connect to database and register it as $app->db
$app->db = new PCDb($datasource);
//Add twitter bootstrap css
$app->layout->addScripts('css/bootstrap.min.css');
//Add (html_class "form-control") to each editable element and (html_class "btn btn-default") to any button.
//You can do that manually too in template file.
$app->events->on('form.before-out', function($event)
{
$form = $event->target;
$editables = array ('input', 'check', 'radio', 'text', 'select', 'listinput');
foreach ($form->elements as $id => $el) {
if (in_array($el['type'], $editables)) {
$el['html']['class'] .= ' form-control';
}
if ($el['type'] == 'button') {
$el['html']['class'] .= ' btn btn-default';
}
$form->elements[$id] = $el;
}
}
);
$search = new PCForm("tpl/bsform.tpl", "bsform");
$grid = new PCGrid ("tpl/bsgrid.tpl", "bsgrid");
if ($search->submitted) {
$grid->filter = $search->values;
if ($app->action == 'showall') {
$grid->filter = $search->values = null;
$search->deleteSession();
}
$grid->saveSession();
$app->message('Form has been sent.', 'alert alert-success');
$app->redirect('bsgrid');
}
$grid->setQuery(
"select * from PRODUCTS where 1
~ and productLine = '{productLine}'
~ and productName like '{productName}%'
~ and productCode like '{productCode}%'"
);
$grid->_SEARCH = $search->html();
print $grid;
?>
Elapsed time: 11.74 ms