Database tables are often used unnecessarily to store information that rarely changes.

Database requests tend to be the slowest part of most applications. Therefore, it does not make sense to use databases to store frequently accessed information that is static in nature. For example, things like country codes and currency codes change very infrequently. Therefore, storing these within code objects makes sense but most frameworks don't offer a convenient way to maintain this static data if it is embedded within PHP code. GenHelm supports models that allow you to maintain data as if it were in a spreadsheet while, internally, the data becomes part of generated classes making the retrevial of the data extremely fast.

php_array_data Model

The php_array_data model allows you to maintain data much like a spreadsheet while the result of stowing the data is a PHP class that can be called to retrieve the data. As an example, consider the following specification showing the abbreviated province codes and tax rates for the Canadian province codes and territories.

Sample tax rate table

Here we show one of the methods by which you could programmatically fetch a cell from this table.

require_once SITE_CLASS_PATH.'array_data/provinces.php';
$prov = new provinces();
$ontario_rate = $prov->get_value('Ontario','tax_rate');

Globals Model

Another common situation involves referencing information throughout the site that is subject to change. In such situations you would like to be able to define this information in one place and refer to it throughout the site. This way, if the information does change you can just update it centrally and the update with ripple throughout the site.

The globals model is used for this purpose. Here we show how globals are used to store phone numbers and address data.

Example of defining globals

Now that these globals have been defined, we can refer to these values from any other specification by using the $globals function as shown here in a bootgrid specification.

Example of specification that uses the globals

Other models that deal with data caching and retrieval include:

  1. datasheet is used to store tabular data without requiring a SQL database.
  2. messages stores various types of messages.
  3. locale saves different language dialects.
  4. translation allowed form labels to be stored externally.