ZF-218: Support column syntax in Zend_Db_Table



I've recently used the ZendFramework and I try to test all functionalities or at least, those I need !

When using the ActiveRecord Zend_Db_Table, I thought that it could be great to have an ActiveRecord working like RoR. For instance, a table Logs :

For the moment you have to do like following :

$log = new Logs();
    'level' => 'MONLEVEL',
    'message' => 'Hop un test'

And I'd rather like to do :

$log = new Logs();
$log->level = 'MONLEVEL';
$log->message = 'Hop un test';

In order to do that, I've changed the Zend_Db_Table like that :

    public function insert($data = null)
        if ($data == null) {
            $data = array();
            foreach ($this->_cols as $col) {
                if (!empty($this->{$col})) {
                    $data[$col] = $this->{$col}; 
        return $this->_db->lastInsertId();

It could be great to externalize the function and to do it for update and delete ! What do you think about it ?


I just put some code tags

I love this feature addition to Zend_Db_Table ^^

Changing fix version to 0.8.0.

Recategorize as Zend_Db_Table component.

Zend_Db_Table already supports something very close to what you describe:

$log = new Logs();

$logRow = $log->fetchNew();
$logRow->level = 'MONLEVEL';
$logRow->message = 'Hop un test';
$logRow->save(); // performs insert() for new row

$logRow->level = 'TUELEVEL';
$logRow->save(); // performs update() for existing row

The Table and Row classes are separate, so you can perform save() either to insert or update a Row, you can instantiate a new Row object, you can have multiple Row objects in your app simultaneously, etc. It's more flexible.

Reworded summary.

The existing Row Data Gateway implementation provides similar functionality and is more flexible than the Ruby on Rails style of syntax. So we are not going to implement the RoR style.