Axiom (v1.2.0)

A lightweight PHP framework
axBaseModel Class Reference

Model Base Class. More...

+ Inheritance diagram for axBaseModel:

Public Member Functions

 __construct (PDO $pdo, $id=null)
 Constructor.
 __sleep ()
 __sleep implementation
 __get ($key)
 __get implementation
 __set ($key, $value)
 __set implementation
 __isset ($key)
 __isset implementation
 getData ()
 create (array $data)
 Create method (Crud)
 retrieve ($id)
 Retrieve method (cRud)
 update (array $data=array())
 Update method (crUd)
 delete ()
 Delete method (cruD)

Protected Member Functions

 _init ($statement)
 Initialize a statement.

Protected Attributes

 $_pdo
 Database connection object.
 $_idKey = "id"
 Name of the identifying key (the PRIMARY KEY of your table in fact)
 $_data = array()
 Record data.
 $_statements = array()
 Statements cache.

Detailed Description

Model Base Class.

Todo:
axBaseModel long description
Warning:
Only tables with strictly one attribute as primary key can be used with this class. For more complex object types, you should describe your own behavior by implementing axModel.
Since:
1.2.0
Author:
Delespierre
License:
http://www.gnu.org/licenses/lgpl.html Lesser General Public Licence version 3

Definition at line 20 of file axBaseModel.class.php.


Constructor & Destructor Documentation

axBaseModel::__construct ( PDO $  pdo,
id = null 
)

Constructor.

If $id is provided, the axModel::retrieve() method will be called with this parameter.

Parameters:
PDO$pdoThe database connection object
mixed$id[optional] [default null]
Exceptions:
InvalidArgumentExceptionIf the $pdo parameter is null
RuntimeExceptionIf the $id parameter did not match an existing record

Implements axModel.

Reimplemented in axMySQLObject.

Definition at line 74 of file axBaseModel.class.php.


Member Function Documentation

axBaseModel::__get ( key)

__get implementation

Retrieves a record data identified by the $key parameter.

Parameters:
string$key
Returns:
mixed

Definition at line 100 of file axBaseModel.class.php.

__isset implementation

Tells if a record data exists.

Parameters:
string$key
Returns:
boolean

Definition at line 126 of file axBaseModel.class.php.

axBaseModel::__set ( key,
value 
)

__set implementation

Updates a record data identified by the $key parameter with the $value parameter.

Note:
no implicit call is done to the axModel::update() method. You will have to update manually.
Parameters:
string$key
mixed$value
Returns:
void

Definition at line 114 of file axBaseModel.class.php.

__sleep implementation

Returns:
array

Definition at line 88 of file axBaseModel.class.php.

axBaseModel::_init ( statement) [abstract, protected]

Initialize a statement.

This method is intended to create the `PDOStatement` objects used by CRUD methods (create, retrieve, update, delete).

A statement is identified by its name:

  • create : for record creation
  • retrieve : for record retrieving
  • update : for record update
  • delete : for deleting a record
Parameters:
string$statementThe statement name
Returns:
PDOStatement

Reimplemented in axMySQLObject.

axBaseModel::create ( array $  data)

Create method (Crud)

Creates the record over the RDBMS using the create prepared statement. Will return false in case of error

Parameters:
array$data
Exceptions:
RuntimeExceptionIf the create statement couldn't be initialized
Returns:
axBaseModel

Implements axModel.

Definition at line 151 of file axBaseModel.class.php.

Delete method (cruD)

Destruct the record over the RDBMS using the delete prepared statement.

Exceptions:
RuntimeExceptionIf the delete statement coulnd't be initialized
Returns:
boolean

Implements axModel.

Definition at line 213 of file axBaseModel.class.php.

Get record data

Will return null if the record hasn't been fetched yet (no call to axModel::retrieve() has been done).

Returns:
array

Implements axModel.

Definition at line 137 of file axBaseModel.class.php.

Retrieve method (cRud)

Reads the record over the RDBMS using the retrieve prepared statement.

Parameters:
mixed$id
Exceptions:
RuntimeExceptionIf the retrieve statement couldn't be initialized
Returns:
axBaseModel

Implements axModel.

Definition at line 171 of file axBaseModel.class.php.

axBaseModel::update ( array $  data = array())

Update method (crUd)

Updates the record over the RDBMS using the update prepared statement. The $data parameter will be merged with the current record data.

Parameters:
array$data[optional] [default array()] The data to add for updating
Exceptions:
RuntimeExceptionIf the update statemetn couldn't be initialized
Returns:
axBaseModel

Implements axModel.

Definition at line 194 of file axBaseModel.class.php.


Field Documentation

array axBaseModel::$_data = array() [protected]

Record data.

Definition at line 38 of file axBaseModel.class.php.

string axBaseModel::$_idKey = "id" [protected]

Name of the identifying key (the PRIMARY KEY of your table in fact)

Definition at line 32 of file axBaseModel.class.php.

PDO axBaseModel::$_pdo [protected]

Database connection object.

Definition at line 26 of file axBaseModel.class.php.

array axBaseModel::$_statements = array() [protected]

Statements cache.

Definition at line 44 of file axBaseModel.class.php.


The documentation for this class was generated from the following file:
 All Data Structures Files Functions Variables