
Public Member Functions | |
| dbo () | |
| changeConnection ($connName) | |
| getConfig () | |
| getLink () | |
| getPrefix () | |
| & | query ($s, $idname=false) |
| & | cachedQuery ($s, $idname=false, $cacheid=false, $ttl=0) |
| escape ($s) | |
| quote ($s) | |
| makeDateTime ($t) | |
| log ($what, $where) | |
| pairs ($params) | |
| getWhereString (&$id, $tableName) | |
| getWhereStringHelper (&$id, $tableName) | |
| find ($method, $params=array(), $tableName=null) | |
| read ($id=null, $fields=null, $tableName=null) | |
| create ($fields, $tableName=null) | |
| delete ($id, $tableName=null) | |
| update ($id, $fields, $tableName=null) | |
| replace ($fields, $tableName=null) | |
| & | describe ($tableName=null) |
| validate ($params, $what) | |
Data Fields | |
| $connection = 'default' | |
| $useTable = false | |
Protected Member Functions | |
| setupDbo ($connName) | |
Protected Attributes | |
| $dboClass = null | |
Definition at line 42 of file model.php.
| & cachedQuery | ( | $ | s, | |
| $ | idname = false, |
|||
| $ | cacheid = false, |
|||
| $ | ttl = 0 | |||
| ) |
Do a query that is cached via the cacheUtility
| string | $s sql-string | |
| string | $idname if set the key of the array is set to the value of this field of the result-array. So the result is not numbered from 0..x but for example the value of the primary key | |
| string | $cacheid the id used to store this query in the cache. if ommited we try to build a suitable key | |
| int | $ttl time to live in seconds (0=infinite) |
Definition at line 185 of file model.php.
References $res, getUtil(), and query().

| changeConnection | ( | $ | connName | ) |
allowes you to switch the current connection dynamically.
| string | $connName name of the new connection to use |
Definition at line 100 of file model.php.
References setupDbo().

| create | ( | $ | fields, | |
| $ | tableName = null | |||
| ) |
insert a record into the database.
$this->create(array('fooId'=>1,'int1'=>10,'int2'=>20));
| array | $fields name=>value pairs to be inserted into the table | |
| string | $tableName insert into this table (if ommitted: use tablename of this model, including prefix) |
Definition at line 508 of file model.php.
References dbo(), query(), and quote().

| dbo | ( | ) |
lazy setup dbo the first time its used
Definition at line 65 of file model.php.
References setupDbo().
Referenced by create(), describe(), escape(), getConfig(), getLink(), getPrefix(), getWhereStringHelper(), makeDateTime(), pairs(), and query().


| delete | ( | $ | id, | |
| $ | tableName = null | |||
| ) |
delete the row whose id is matching
$this->delete(5); $this->delete(array('rowId'=>10)); $this->delete(array( 'rowId'=>20, 'and', 'parentId'=>10 ));
| mixed | $id primary key of row to delete | |
| string | $tableName delete from this table (if ommitted: use tablename of this model, including prefix) |
Definition at line 540 of file model.php.
References getWhereString(), and query().

| & describe | ( | $ | tableName = null |
) |
tries to reduce all fields of the given table to basic datatypes
| string | $tableName optional tablename to use |
Definition at line 596 of file model.php.
References CacheUtility::CM_FILE, dbo(), and getUtil().

| escape | ( | $ | s | ) |
| find | ( | $ | method, | |
| $ | params = array (), |
|||
| $ | tableName = null | |||
| ) |
select rows using various methods (see $method for full list)
$rows = $this->find('all',array( 'conditions' => array( // WHERE conditions to use. default all elements are AND, just add 'or' to the condition-array to change this 'field' => $thisValue, 'or', 'field2'=>$value2, 'field3'=>$value3, 'field4'=>$value4 ), 'fields' => array( //array of field names that we should return. first field name is used as array-key if you use method 'list' and listby is unset 'field1', 'field2' ), 'order' => array( //string or array defining order. you can add DESC or ASC 'created', 'field3 DESC' ), 'group' => array( //fields to GROUP BY 'field' ), 'listby' => array( //only if find('list'): fields to arrange result-array by 'field1','field2' ), 'limit' => 50, //int, how many rows per page 'page' => 1, //int, which page, starting at 1 ),'mytable');
| string | $method can be 'all','list','count','first','neighbors' | |
| array | $params see example | |
| mixed | $tableName string or null to use modelname |
| getConfig | ( | ) |
| getLink | ( | ) |
| getPrefix | ( | ) |
| getWhereString | ( | &$ | id, | |
| $ | tableName | |||
| ) |
| getWhereStringHelper | ( | &$ | id, | |
| $ | tableName | |||
| ) |
do the actual work for getWhereString(). analyse strings and branch for arrays
| mixed | $id | |
| string | $tableName needed to generate a primary key name |
Definition at line 288 of file model.php.
References dbo(), and quote().

| log | ( | $ | what, | |
| $ | where | |||
| ) |
convenience method for writeLog
| string | $what what to log | |
| string | $where where to log (KATA_DEBUG OR KATA_ERROR) |
Definition at line 246 of file model.php.
References writeLog().

| makeDateTime | ( | $ | t | ) |
| pairs | ( | $ | params | ) |
turn the given array into "name=value,name=value" pairs suitable for INSERT or UPDATE-sqls. strings are automatically escaped
| array | $params the data |
Definition at line 254 of file model.php.
References dbo(), and quote().
Referenced by replace(), and update().


| & query | ( | $ | s, | |
| $ | idname = false | |||
| ) |
execute an actual query on the database
| string | $s the sql to execute | |
| string | $idname can be used to have the keys of the returned array equal the value ob the column given here (instead of just heaving 0..x as keys) |
Reimplemented in ClusterModel.
Definition at line 167 of file model.php.
References dbo().
Referenced by cachedQuery(), create(), delete(), read(), replace(), and update().


| quote | ( | $ | s | ) |
enclose string in quotes and escape it
Definition at line 228 of file model.php.
Referenced by create(), getWhereStringHelper(), and pairs().

| read | ( | $ | id = null, |
|
| $ | fields = null, |
|||
| $ | tableName = null | |||
| ) |
read data from the database. $rows = $this->read(5); $rows = $this->read(array('foobarId'=>5)); $rows = $this->read(array( 'foobarId'=>6, 'and', 'someId'=>2 ));
| mixed | $id read the row with this primary key (if null: all rows) | |
| array | $fields return these colums (if null: all fields) | |
| string | $tableName read from this table (if ommitted: use tablename of this model, including prefix) |
Definition at line 484 of file model.php.
References getWhereString(), and query().

| replace | ( | $ | fields, | |
| $ | tableName = null | |||
| ) |
update a row or insert a new record if no previous row is found
$this->replace(array( 'fooId'=>10, 'data1'=>20 ));
| mixed | $id primary key of row to replace | |
| array | $fields name=>value pairs of new values | |
| string | $table replace from this table (if ommitted: use tablename of this model, including prefix) |
Definition at line 584 of file model.php.
References pairs(), and query().

| setupDbo | ( | $ | connName | ) | [protected] |
load dbo-class, give dbconfig to class
| string | $connName name of the connection to use |
Definition at line 76 of file model.php.
References classRegistry::getObject(), and kataUse().
Referenced by changeConnection(), and dbo().


| update | ( | $ | id, | |
| $ | fields, | |||
| $ | tableName = null | |||
| ) |
update a row whose id is matching
$this->update(array( 'fooId'=>10, 'data1'=>20 ));
| mixed | $id primary key of row to update | |
| array | $fields name=>value pairs of new values | |
| string | $tableName update data in this table (if ommitted: use tablename of this model, including prefix) |
Definition at line 563 of file model.php.
References getWhereString(), pairs(), and query().

| validate | ( | $ | params, | |
| $ | what | |||
| ) |
checks the given values of the array match certain criterias
| array | $params key/value pair. key is the name of the key inside the $what-array, value is a "VALID_" define (see above) or the name of a function that is given the string (should return bool wether the string validates) | |
| array | $what the actual data |
1.5.8