PHP Extension & Application RepositoryPyrus - A few PEAR Compatible Packages


Using DB_DataObject_FormBuilder, SearchBuilder can rapidly put together a search form and then use the submission to search the specified table(s). The results may either be printed in HTML or returned as an array of DataObjects. The main advantage of using something like this is speed and automation. Create the necessary DataObjects, joining if necessary using joinAdd() and then list the fields which should be searched. Extra search parameters may be added if required which map to where subclauses. SearchBuilder also uses the fb_linkDisplayFields attribute of your DataObjects to display foreign keys correctly. CSS Hooks are provided for the results table, so it can be customised to a certain degree.

Documentation and Demonstration to follow...

A Short Tutorial

The API for SearchBuilder was originally designed to be as close as possible to FormBuilder, so as to limit any learning curves.


require_once 'DB/DataObject.php';

$do =& DB_DataObject::factory('some_table_to_search');

// create the object using new instead of a create function
$builder =& new DB_DataObject_SearchBuilder($do);

// turn on paged searching if required
$builder->doPaging = true;

// use the searchFields array to specify the search parameters (analogous to fieldsToRender)
$builder->searchFields = array('first_name','surname','dob');

// call getForm just as with FormBuilder
$form =& $builder->getForm();

// display the search form

// validate and process the same as with FormBuilder
if ($form->validate())
// print the results using the default html
echo $builder->resultsToHtml();


Should result in some html like:

Search Person
First Name
Date of Birth --
Search Results
Found 167 results, displaying 1 to 10
Surname First Name Date Of Birth
Aarons George 1975-03-15
Aary Susan 1983-08-05
Abbey Timothy 1980-01-09
Abbey John 1987-11-04
Abbims Paul 1990-03-27
Abbott Judy 1989-12-29
Abella Joeseph 1953-09-26
Abette Stephanie 1994-04-14
Abrahams David 1956-07-23
Acacia Ray 1978-05-04
  Last >>  Next > Logo