Get Primary Key out of Zend_Db_Table_Rowset Object

只愿长相守 提交于 2019-12-11 06:26:20

问题


inside of my Zend_Db_Table_Rowset Object i found this:

["_primary:protected"]

... does anybody if theres a way to access this? ... maybe something like

$rowsetObject->getPrimary()

Thanks for your help, Alex


回答1:


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();
    }
}



回答2:


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;
   }
}


来源:https://stackoverflow.com/questions/2487523/get-primary-key-out-of-zend-db-table-rowset-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!