Zend does provide a decent table abstraction (screw you mysql/mysqli functions) with some ActiveRecord like capabilities i.e.:
$table = new MyTable(); //Assumes database adapter was initialized
$newEntry = array('name'=>"TK",'state'=>"TX");
$newEntry['id'] = $table->insert($newEntry);
$oldEntry = $table->fetchRow(
$table->select()->where("id = ?",$newEntry['id']))
->toArray();
Not too shabby, an ok query builder with auto-escaping, but I still feel like something is missing...
Thankfully PHP5 introduced some decent meta programming/reflection capabilities. Of particular interest is the "magic" function __call($method,$arguments).
class My_Model_DbTable_Abstract extends Zend_Db_Table_Abstract
{
public function __call($method,$arguments){
if(strncmp($method,"getBy",5) == 0){
if(count($arguments) != 1)
throw new My_Exception("getBy(value) takes one argument");
$fieldName = strtolower(substr($method,5));
if(isset($this->_metadata,$fieldName))
return $this->_getBy($fieldName,$arguments[0]);
throw new My_Exception("$this->_name has no field '$fieldName'");
}
throw new My_Exception("Unknown method: '$method'");
}
public function _getBy($col,$value){
$result = $this->fetchRow($this->select()->where("$col = ?",$value));
return (null == $result) ? null : $result->toArray();
}
}
...
$oldEntry = $table->getById($newEntry['id']);
I'm terrified I might start writing Django's ORM in PHP, but I really don't have the time. The eventual task of writing a Zend_Form for every table I create is just as daunting... maybe I just need to Google around some more