ZF-1144: Support default table in constructor of custom Row

Issue Type: New Feature Created: 2007-03-27T13:52:52.000+0000 Last Updated: 2009-01-08T06:53:31.000+0000 Status: Resolved Fix version(s): - 1.8.0 (30/Apr/09)

Reporter: Bill Karwin (bkarwin) Assignee: Jurrien Stutterheim (norm2782) Tags: - Zend_Db_Table

Related issues: - ZF-191



Jeff Bailey writes:

I have a Class that I'm inheriting from Zend_Table_Db_Row_Abstract to use as a customClass in a table, let's call it User. This works fine for retrieving rows and giving me all of my attached logic, update checks and whatnot.

What I'd like to be able to do is use it naturally for creating empty objects, so

<pre class="highlight">
$aUser = new User();

In order to do this, I've cooked up a constructor that will work:

<pre class="highlight">
class User extends Zend_Db_Table_Row_Abstract
    private $_tableName = "UserTable";

    public function __construct(array $config = array())
        if (empty($config["table"])) {
            $config["table"] = new $this->_tableName();
            $info = $config["table"]->info();
            $keys = array_values($info[Zend_Db_Table_Abstract::COLS]);
            $vals = array_fill(0, count($keys), NULL);
            $config["data"] = array_combine($keys, $vals);


I think that this type of logic would be nice to have as the default constructor for Zend_Db_Table_Row_Abstract.


Posted by Bill Karwin (bkarwin) on 2007-03-27T13:53:19.000+0000

I've used the fetchNew method, but then it means that the business logic needs to know about the table subclasses.

<pre class="highlight">
$userTable = new UserTable();
$aUser = UserTable->fetchNew();

feels less natural than:

<pre class="highlight">
$aUser = new User();

and also makes for code that is slightly easier to test with null objects.

Posted by Bill Karwin (bkarwin) on 2007-04-17T17:55:45.000+0000

We should allow primary key fields to be set. This issue would be much easier to solve if that were true. So I'm marking it as a dependency.

Posted by Wil Sinclair (wil) on 2008-03-25T20:43:58.000+0000

Please categorize/fix as needed.

Posted by Wil Sinclair (wil) on 2008-04-18T13:12:06.000+0000

This doesn't appear to have been fixed in 1.5.0. Please update if this is not correct.

Posted by Jurrien Stutterheim (norm2782) on 2009-01-08T06:53:31.000+0000

Resolved in r.13552

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.