问题描述
在我的 Zend_Db_Table_Rowset 对象中,我发现了这个:
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
推荐答案
Zend_Db_Table_Rowset
没有属性 _primary
.您所指的是您从中获得行集的 Zend_Db_Table
实例或行集内的 Zend_Db_Table_Row
实例.
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.
要从 Zend_Db_Table
实例获取主键,您可以执行以下操作:
For getting the primary key from a Zend_Db_Table
instance you can do:
$tableInstance->info('primary')
要从 Zend_Db_Table_Row
实例获取主键,您可以获取表实例并对其调用 info()
:
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')
请注意,当行断开连接时,这将不起作用,因为这样 getTable()
将返回 null
.
Note that this will not work when the row is disconnected, because then getTable()
will return null
.
或者,当使用自定义 Zend_Db_Table_Row
时,您可以添加一个代理到 _getPrimaryKey()
的方法:
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();
}
}
这篇关于从 Zend_Db_Table_Rowset 对象中获取主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!