A quick post to show how one can easily implement a findByField wrapper in Zend_Db_Table:
/**
* Implements a simple findByField wrapper
*/
public function __call($method, $args) {
if (preg_match('/^findBy([a-zA-Z0-9]+)$/', $method, $parts)) {
$field = strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $parts[1]));
if (!in_array($field, $this->_cols)) {
throw new Zend_Db_Table_Exception(sprintf('\'%s\' field not in row', $field));
} else {
$db = $this->getAdapter();
$where = $db->quoteInto($db->quoteIdentifier($field).' = ?', $args[0]);
return $this->fetchAll($where);
}
}
}
What it does is basically trapping any non-existant method call and check if the corresponding field exists, after converting CamelCasing to underscore_notation (eg: FooBar becomes foo_bar).