Model Class Reference

Inheritance diagram for Model:

Inheritance graph
[legend]

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

Detailed Description

Definition at line 42 of file model.php.


Member Function Documentation

& cachedQuery ( s,
idname = false,
cacheid = false,
ttl = 0 
)

Do a query that is cached via the cacheUtility

Parameters:
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().

Here is the call graph for this function:

changeConnection ( connName  ) 

allowes you to switch the current connection dynamically.

Parameters:
string $connName name of the new connection to use

Definition at line 100 of file model.php.

References setupDbo().

Here is the call graph for this function:

create ( fields,
tableName = null 
)

insert a record into the database.

$this->create(array('fooId'=>1,'int1'=>10,'int2'=>20));

Parameters:
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().

Here is the call graph for this function:

dbo (  ) 

lazy setup dbo the first time its used

Returns:
object intialized dbo-class

Definition at line 65 of file model.php.

References setupDbo().

Referenced by create(), describe(), escape(), getConfig(), getLink(), getPrefix(), getWhereStringHelper(), makeDateTime(), pairs(), and query().

Here is the call graph for this function:

Here is the caller graph for this function:

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 ));

Parameters:
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().

Here is the call graph for this function:

& describe ( tableName = null  ) 

tries to reduce all fields of the given table to basic datatypes

Parameters:
string $tableName optional tablename to use
Returns:
array

Definition at line 596 of file model.php.

References CacheUtility::CM_FILE, dbo(), and getUtil().

Here is the call graph for this function:

escape ( s  ) 

escape possibly harmful strings so you can safely append them to an sql-string

Definition at line 221 of file model.php.

References dbo().

Here is the call graph for this function:

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');

Parameters:
string $method can be 'all','list','count','first','neighbors'
array $params see example
mixed $tableName string or null to use modelname

Definition at line 386 of file model.php.

getConfig (  ) 

Definition at line 109 of file model.php.

References dbo().

Here is the call graph for this function:

getLink (  ) 

Definition at line 117 of file model.php.

References dbo().

Here is the call graph for this function:

getPrefix (  ) 

return the prefix configured for this connection

Returns:
string

Definition at line 155 of file model.php.

References dbo().

Here is the call graph for this function:

getWhereString ( &$  id,
tableName 
)

construct a suitable where-clause for a query

Parameters:
mixed $id
string $tableName needed to generate a primary key name
Returns:
string full 'WHERE x=' string

Definition at line 275 of file model.php.

Referenced by delete(), read(), and update().

Here is the caller graph for this function:

getWhereStringHelper ( &$  id,
tableName 
)

do the actual work for getWhereString(). analyse strings and branch for arrays

Parameters:
mixed $id
string $tableName needed to generate a primary key name
Returns:
string 'x=y AND x=z' string without 'WHERE'

Definition at line 288 of file model.php.

References dbo(), and quote().

Here is the call graph for this function:

log ( what,
where 
)

convenience method for writeLog

Parameters:
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().

Here is the call graph for this function:

makeDateTime ( t  ) 

turn a unix timestamp into datetime-suitable data

Parameters:
integer $t unix time
Returns:
string sql-statement

Definition at line 237 of file model.php.

References dbo().

Here is the call graph for this function:

pairs ( params  ) 

turn the given array into "name=value,name=value" pairs suitable for INSERT or UPDATE-sqls. strings are automatically escaped

Parameters:
array $params the data

Definition at line 254 of file model.php.

References dbo(), and quote().

Referenced by replace(), and update().

Here is the call graph for this function:

Here is the caller graph for this function:

& query ( s,
idname = false 
)

execute an actual query on the database

Parameters:
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().

Here is the call graph for this function:

Here is the caller graph for this function:

quote ( s  ) 

enclose string in quotes and escape it

Definition at line 228 of file model.php.

Referenced by create(), getWhereStringHelper(), and pairs().

Here is the caller graph for this function:

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 ));

Parameters:
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().

Here is the call graph for this function:

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 ));

Parameters:
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().

Here is the call graph for this function:

setupDbo ( connName  )  [protected]

load dbo-class, give dbconfig to class

Parameters:
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().

Here is the call graph for this function:

Here is the caller graph for this function:

update ( id,
fields,
tableName = null 
)

update a row whose id is matching

$this->update(array( 'fooId'=>10, 'data1'=>20 ));

Parameters:
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().

Here is the call graph for this function:

validate ( params,
what 
)

checks the given values of the array match certain criterias

Parameters:
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
Deprecated:
31.04.2009

Definition at line 617 of file model.php.


Field Documentation

$connection = 'default'

Definition at line 47 of file model.php.

$dboClass = null [protected]

Definition at line 59 of file model.php.

$useTable = false

Definition at line 53 of file model.php.


The documentation for this class was generated from the following file:

Generated on Mon Apr 27 16:29:08 2009 for kata by  doxygen 1.5.8