开发者

Get Primary Key out of Zend_Db_Table_Rowset Object

开发者 https://www.devze.com 2022-12-23 21:22 出处:网络
inside of my Zend_Db_Table_Rowset Object i found this: [\"_primary:protected\"] ... does anybody if theres a开发者_JAVA技巧 way to access this? ... maybe something like

inside of my Zend_Db_Table_Rowset Object i found this:

["_primary:protected"]

... does anybody if theres a开发者_JAVA技巧 way to access this? ... maybe something like

$rowsetObject->getPrimary()

Thanks for your help, Alex


Zend_Db_Table_Rowset has no property _primary. What you are refering to is either the Zend_Db_Table instance you got the Rowset from or a Zend_Db_Table_Row instance inside the Rowset.

For getting the primary key from a Zend_Db_Table instance you can do:

$tableInstance->info('primary')

For getting the primary key from a Zend_Db_Table_Row instance you can get the table instance and call info() on it:

$rowInstance->getTable()->info('primary')

Note that this will not work when the row is disconnected, because then getTable() will return null.

Or, when using a custom Zend_Db_Table_Row you can add a method that proxies to _getPrimaryKey():

class My_Db_Table_Row extends Zend_Db_Table_Row
{
    public function getPrimaryKey()
    {
        return $this->_getPrimaryKey();
    }
}


Since this variable is protected, you can extend Zend_Db_Table_Rowset and define getPrimary() function yourself, e.g.

class My_Zend_Db_Table_Rowset extends Zend_Db_Table_Rowset {
//put your code here

   function getPrimary() {
      return $this->_primary;
   }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消