PHP Class Controller_Data, atk4

Inheritance: extends Controller_Base
Show file Open project: atk4/atk4 Class Usage Examples

Public Properties

Property Type Description
$auto_track_element When controller is added into model, the model will automatically keep track of it and will not dispose of it.
$default_exception
$supportConditions Conditions can be set on non-primary field. This capability of data controller allows your model to use methods such as addCondition, loadBy, tryLoadBy etc. Each of those methods can be supplied with two arguments - the field and value and exact matching will be used. For three-argument use, see property $supportOperators.
$supportLimit Limit makes it possible to specify count / skip for the model, which is necessary for pagination.
$supportOperators Controller is required to support '>', '<', '=', '!=', '<=', '>=' operators even if database uses diffirent notation, due to consistency. If database supports additional operators, you can list them as an array in this attribute, e.g.: ['like','is','is not']. You may also set $supportOperators='all' which will indicate that this controller supports all possible operators, although this is not advised.
$supportOrder Controller allows re-ordering data set by non-primary field in either ascending or descending order. Models support ordering on multiple fields. If controller does not support multiple ordering fields, then the last field to be used for ordering must take precedence.
$supportRef This would be supported by most data controllers.

Public Methods

Method Description
d ( $model )
delete ( $model, $id ) Locate and remove record in the storade with specified $id. Return true if record was deleted or false if it wasn't found. In most cases, the record data will first be loaded and then deleted, just to make sure the record is accessible with specified conditions, so you can silently ignore error.
loadById ( $model, $id ) Locate and load data for a specified record. If data backend supports selective loading of fields, you may call model->getActualFields to get a list of required fields for a model. When non-array is returned, you should load all fields.
loadCurrent ( $model, &$cursor ) Load next data row from cursor.
prefetchAll ( $model ) Create a new cursor and load model with the first entry. Returns cursor, which will then be passed to loadCurrent() for loading more results.
save ( $model, $id, $data ) Writes record containing $data into the data store under id=$id.
setSource ( $model, $data ) Associates model with the collection/table in this data store identified by second argument. For instance for Controller_Data_SQL the second argument would be a table.

Method Details

d() public method

public d ( $model )

delete() abstract public method

Locate and remove record in the storade with specified $id. Return true if record was deleted or false if it wasn't found. In most cases, the record data will first be loaded and then deleted, just to make sure the record is accessible with specified conditions, so you can silently ignore error.
abstract public delete ( $model, $id )

loadById() abstract public method

Locate and load data for a specified record. If data backend supports selective loading of fields, you may call model->getActualFields to get a list of required fields for a model. When non-array is returned, you should load all fields.
abstract public loadById ( $model, $id )

loadCurrent() public method

Load next data row from cursor.
public loadCurrent ( $model, &$cursor )

prefetchAll() abstract public method

If the data store does not support cursors, then fetch all data and return array. loadCurrent will automatically array_shift one record on each call.
abstract public prefetchAll ( $model )

save() abstract public method

If the ID field can vary, consult $model->id_field. You do not have to worry about default fileds, because their values will automatically be in $data. If $id is null then new record must be created. If $id is specified, then record must be overwritten. Method must return $id of stored record. This method may throw exceptions.
abstract public save ( $model, $id, $data )

setSource() public method

All necessary data must be stored in $model->_table[$this->short_name] to avoid conflicts between different controllers and to allow user to use one controller with multiple models.
public setSource ( $model, $data )

Property Details

$auto_track_element public property

When controller is added into model, the model will automatically keep track of it and will not dispose of it.
public $auto_track_element

$default_exception public property

public $default_exception

$supportConditions public property

Conditions can be set on non-primary field. This capability of data controller allows your model to use methods such as addCondition, loadBy, tryLoadBy etc. Each of those methods can be supplied with two arguments - the field and value and exact matching will be used. For three-argument use, see property $supportOperators.
public $supportConditions

$supportLimit public property

Limit makes it possible to specify count / skip for the model, which is necessary for pagination.
public $supportLimit

$supportOperators public property

Controller is required to support '>', '<', '=', '!=', '<=', '>=' operators even if database uses diffirent notation, due to consistency. If database supports additional operators, you can list them as an array in this attribute, e.g.: ['like','is','is not']. You may also set $supportOperators='all' which will indicate that this controller supports all possible operators, although this is not advised.
public $supportOperators

$supportOrder public property

Controller allows re-ordering data set by non-primary field in either ascending or descending order. Models support ordering on multiple fields. If controller does not support multiple ordering fields, then the last field to be used for ordering must take precedence.
public $supportOrder

$supportRef public property

This would be supported by most data controllers.
public $supportRef