Why am I getting this strange error when working with findDependantRowset and Zend Framework?
PHP is throwing this error:
Fatal error: Call to a member function getAdapter() on a non-object in C:\Program Files\Zend\ZendServer\share\ZendFramework\library\Zend\Db\Table\Row\Abstract.php on line 869
... when I call this code:
$item = $itemMapper->find(1); // Find item with id of 1
$item->findDependentRowset("Application_Model_DbTable_SubItem");
I have the following other classes:
models/DBTable/Item.php
:
class Application_Model_DbTable_Item extend开发者_高级运维s Zend_Db_Table_Abstract {
/** Table name */
protected $_name = 'items';
}
models/DBTable/SubItem.php
:
class Application_Model_DbTable_SubItem extends Zend_Db_Table_Abstract {
/** Table name */
protected $_name = 'subitems';
protected $_referenceMap = array(
'Item' => array(
'columns' => 'items_id',
'refTableClass' => 'Application_Model_DbTable_Item',
'refColumns' => 'items_id'
)
);
}
All my models, mappers, and database tables are set up correctly, as far as I know. Accessing a model through the wrapper and fetchAll
works fine.
My models extend Zend_Db_Table_Row
. Why is it giving me this error?
FYI:
The line the error message cites looks like this:
public function findDependentRowset($dependentTable, $ruleKey = null, Zend_Db_Table_Select $select = null){
$db = $this->_getTable()->getAdapter(); // <<<< there it is
...
I figured it out. Apparently, I was under the assumption that the result of find()
returned by my mapper class was a Zend_Db_Table_Row
object. I even tried using instanceOf
to verify this, but I either used it incorrectly, or it lied to me.
The object returned by my mapper was simply a Model.
Calling find()
on the Application_Model_DbTable_Table
object returns a rowset, and current()
works currently. After using this approach, I was able to call findDependentRowset()
successfully.
精彩评论