pclib
3.0.0
Lightweight PHP framework
|
Base class for any application model. More...
Public Member Functions | |
__construct ($tableName, array $values=array()) | |
Create new model. More... | |
setTemplate (Tpl $template) | |
Use an existing template object. More... | |
getTemplate () | |
Return model template. More... | |
getColumns () | |
Return model database columns. More... | |
getTableName () | |
Return underlying database table name. | |
find ($id) | |
Find record by primary key and load values from db. More... | |
hasColumn ($name) | |
Check if model has column $name. More... | |
__get ($name) | |
PHP magic method. More... | |
__set ($name, $value) | |
PHP magic method. More... | |
related ($name) | |
Return related model or selection of models. More... | |
isInDb ($value=null) | |
Get or set flag indicating if model has database representation. More... | |
save () | |
Save model to the database. More... | |
setRole ($role) | |
Choose access role. More... | |
hasRight ($action) | |
Test if current role has right do $action. More... | |
delete () | |
Delete model in database, set Model->inDb flag to false. More... | |
onError ($action) | |
Occurs on validation error. | |
validate ($action='') | |
Validate values of the model against template. More... | |
getErrors () | |
Return array of validator errors. More... | |
getValues () | |
Get model values. More... | |
setValues (array $values) | |
Set model values. More... | |
toArray () | |
Get model values. More... | |
setValue ($name, $value) | |
Set column $name to $value. | |
getValue ($name) | |
Get $value of column $name. | |
__toString () | |
PHP magic method. More... | |
Public Member Functions inherited from BaseObject | |
loadDefaults ($className=null) | |
Load default parameters of class $className into object instance. | |
setProperties (array $defaults) | |
Set public properties of object from the array. More... | |
Static Public Member Functions | |
static | create ($tableName, array $values=array(), $doSave=true) |
Create new model and store it to database. More... | |
static | className ($tableName) |
Return model class name for $tableName and include model source file. More... | |
Static Public Member Functions inherited from BaseObject | |
static | defaults () |
Set or retireve default parameters of the object. More... | |
Data Fields | |
$db | |
var Db | |
Data Fields inherited from BaseObject | |
$serviceLocator | |
var function() Return service object when requested with service(). | |
Protected Member Functions | |
createTemplate () | |
Create template object from template file, or use default template. More... | |
createDefaultTemplate () | |
Create default template object (empty). More... | |
getModel ($tableName, $id=null) | |
Return model for table $tableName. | |
selection ($from=null) | |
Return orm\Selection class. | |
insert () | |
Insert new row into table with model values. | |
update () | |
Update model values in database with actual state. | |
validateRelated () | |
Check if rules in "event ondelete" are passed. | |
deleteRelated () | |
Delete related models as defined in "event ondelete". | |
Protected Member Functions inherited from BaseObject | |
service ($service, $default=null) | |
Try acquire $service and load it into property $this->$service. More... | |
Static Protected Member Functions | |
static | getFilePath ($name, $ext) |
Return path to model/template file. More... | |
Protected Attributes | |
$tableName | |
Name of source database table. | |
$inDb = false | |
Is model stored in database? | |
$template | |
var Tpl | |
$validator | |
var Validator | |
$values = array() | |
Array of model values. | |
$modified = array() | |
Array of modified column names. | |
$accessRole | |
Role used by model for data access. | |
Base class for any application model.
__construct | ( | $tableName, | |
array | $values = array() |
||
) |
Create new model.
string | $tableName | Database table |
array | $values | Model values |
__get | ( | $name | ) |
PHP magic method.
Implements following features:
Reimplemented from BaseObject.
__set | ( | $name, | |
$value | |||
) |
PHP magic method.
Implements following features:
Reimplemented from BaseObject.
__toString | ( | ) |
|
static |
Return model class name for $tableName and include model source file.
string | $tableName | Database table |
|
static |
Create new model and store it to database.
string | $tableName | Database table |
array | $values | Model values |
bool | $doSave | Save to db? |
|
protected |
Create default template object (empty).
|
protected |
Create template object from template file, or use default template.
delete | ( | ) |
Delete model in database, set Model->inDb flag to false.
find | ( | $id | ) |
Find record by primary key and load values from db.
int | $id | primary key |
getColumns | ( | ) |
Return model database columns.
getErrors | ( | ) |
Return array of validator errors.
|
staticprotected |
Return path to model/template file.
Override for your own model/template names and locations. Default location: 'models/*'
getTemplate | ( | ) |
getValues | ( | ) |
Get model values.
hasColumn | ( | $name | ) |
Check if model has column $name.
hasRight | ( | $action | ) |
Test if current role has right do $action.
string | array | $action |
isInDb | ( | $value = null | ) |
Get or set flag indicating if model has database representation.
However, actual values can differ from database - see $this->modified.
related | ( | $name | ) |
Return related model or selection of models.
Relation $name must be defined in template elements
save | ( | ) |
Save model to the database.
setRole | ( | $role | ) |
Choose access role.
Role permissions for the model can be defined in template.
string | $role |
setValues | ( | array | $values | ) |
Set model values.
array | $values |
toArray | ( | ) |
validate | ( | $action = '' | ) |
Validate values of the model against template.
Set validation errors - see getErrors()
string | $action | insert|update|delete |