从 Zend_Db_Table_Rowset 对象中获取主键 [英] Get Primary Key out of Zend_Db_Table_Rowset Object

查看:23
本文介绍了从 Zend_Db_Table_Rowset 对象中获取主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 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 对象中获取主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆