Datasources

Datasources are PHP objects, that can be used to populate elements like the Enum? or Set? element. The have to implement the following interface:

class patForms_Datasource_Foo {
    function getValues($element) {
        // return the array containing the data for the element
    }
}

patForms currently provides two ready-to-use data sources:

  • Countries, can be used to build a drop-down to select a country ISO code
  • Propel, can be used to populate a drop-down with a list from a database table using Propel (alpha)

Using datasources

Using a datasource is easy. All you need to to is create the datasource object (or let patForms create it for you) and attach it to the element you want it to populate:

$countries = &patForms::createDatasource('Countries');   

// get the element
$el =& $form->getElementByName('country');

// tell the element to use the datasource object
$el->setDataSource($countries);

The createDatasource() method will search for a class patForms_Datasource_Countries in the paths you defined and create a new instance of this class.