View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFDEV:Zend Proposal Zone Template}


[Borja Fernandez|]

1.2 - 19 July 2006: Updated from community comments.

An object that wraps a row in a database table or view, encapsulates the database access, and allows to adds domain logic on that data.





* Zend_Db
* Zend_Exception

Define a Class based on Zend_Db_Model_Abstract and add your own domain logic.

* Zend_Db_Model
* Zend_Db_Model_Exception

// Initialization
$model = new Zend_Db_Model();
$model->setModelsDir(APP . '/models/');

// This return an object based on
// APP . '/models/' . Users.php class
$user = $model->factory('users');

// Basic insert

// associative array insert

// Basic update

// Basic delete


/** Example model file based on this table
** CREATE TABLE users (
** username varchar(12) not null primary key,
** password varchar(12) not null,
** group_id unsigned int
** );
** CREATE TABLE groups(
** id unsigned int primary key,
** name varchar(12) not null
** );

// Users.php on APP . '/models/' dir
class Users Extends Zend_Db_Model_Abstract {
public function loadObjects() {

class Groups Extends Zend_Db_Model_Abstract {}

// Change group name if is an admin user
if ($users->group->name == 'ADMIN') {
$users->group->name = 'SUPERADMIN';

// Others uses
echo $users->lastLogin->dateValue('Year: %Y');

factory($model,$id = null)

public function __construct($object,$id = null)
private function _checkDb()
private function describeTable()
public function insert()
public function update()
public function delete()
public function toArray()
public function getAdapter()
public function assignArray($data)
public function addField($field,$data,$filter = null)
public function key($keyname = null)
public function keyvalue()
public function table($tablename = null)
public function assignPostVars()
public function find($id)