ZF-218: Support column syntax in Zend_Db_Table

Issue Type: Improvement Created: 2006-07-10T01:37:08.000+0000 Last Updated: 2007-07-05T14:43:13.000+0000 Status: Resolved Fix version(s): - 0.9.2 (06/Apr/07)

Reporter: Jonathan Adami (pitilezard) Assignee: Bill Karwin (bkarwin) Tags: - Zend_Db_Table

Related issues: - ZF-38




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 :

<pre class="highlight">
$log = new Logs();
    'level' => 'MONLEVEL',
    'message' => 'Hop un test'

And I'd rather like to do :

<pre class="highlight">
$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 :

<pre class="highlight">
    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 ?


Posted by Jonathan Adami (pitilezard) on 2006-07-10T06:45:43.000+0000

I just put some code tags

Posted by Superbiji (superbiji) on 2006-07-17T03:49:27.000+0000

I love this feature addition to Zend_Db_Table ^^

Posted by Bill Karwin (bkarwin) on 2006-11-13T15:22:39.000+0000

Changing fix version to 0.8.0.

Posted by Bill Karwin (bkarwin) on 2007-01-05T17:06:26.000+0000

Recategorize as Zend_Db_Table component.

Posted by Bill Karwin (bkarwin) on 2007-02-26T21:48:47.000+0000

Zend_Db_Table already supports something very close to what you describe:

<pre class="highlight">
$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.

Posted by Bill Karwin (bkarwin) on 2007-04-04T14:40:24.000+0000

Reworded summary.

Posted by Bill Karwin (bkarwin) on 2007-04-04T14:41:29.000+0000

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.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.