Badtable


Preparing your models

You can customise your model tables, specifying callback functions that will prepare field values for displaying in a table.

  1. Open up the model in a text editor.
  2. Edit the models validation array:
    • Add a ['label'] attribute to define the column header for this field.
    • Specify a ['table_callback'] attribute if you need to prep a field for table use. The table_callback should specifie either a loaded PHP function or a method of the model. Badtable will always pass the field value as first parameter to these functions, any other parameters can be specified by a comma seperated string between square brackets, [var1,var2], much like the validation rules attribute.
  3. Save your model.

Example

In this example we are triming the description of any white space before it is added in the table. We are also formatting the created and updated datetime fields to human readable strings.

class Group extends Datamapper {
			
	var $validation = array(		
		'id' => array(
			'rules' => array(),
			'label' => 'ID'
		),
		'name' => array(
			'rules' => array('required', 'max_length' => 128),
			'label' => 'Name'
		),
		'description' => array(
			'rules' => array('required'),
			'label' => 'Description',
			'type'	=> 'textarea'
		),
		'updated' => array(
			'rules' => array(),
			'label' => 'Updated'
			'table_callback' => 'mysqldatetime_to_date[d/m/y h:i:s]'
		),		
		'created' => array(
			'rules' => array(),
			'label' => 'Created',
			'table_callback' => 'mysqldatetime_to_date[d/m/y]'
		)
	);
}