2

我有两个表,每个表都有 Class Albums 和 Category 如下:

class Application_Model_DbTable_Albums extends Zend_Db_Table_Abstract
{

    protected $_name = 'albums';
    private $_custom_message = '';

    protected $_referenceMap = array(
        'CategoryTypes' => array(
            'columns' => array('category_id'),
            'refTableClass' => 'Category',
            'refColumns' => array('id')
        )
    );
}

class Application_Model_DbTable_Category extends Zend_Db_Table_Abstract {

protected $_name = 'category';

protected $_dependentTables = array('Albums');
}

在我的 IndexController 编辑操作中,我有以下代码:

$category = new Application_Model_DbTable_Category();

$cat_id = $category->find(1);
$cat_3 = $cat_id->current();

$user_cat = $cat_3->findDependentRowset('Albums');

我得到这个异常消息。注释掉 $user_cat 不会得到异常消息

Exception information:

Message: File "Albums.php" does not exist or class "Albums" was not found in the file
Stack trace:

#0 C:\Program Files\Zend\Apache2\htdocs\zf-tutorial\library\Zend\Db\Table\Row\Abstract.php(872): Zend_Db_Table_Row_Abstract->_getTableFromString('Albums')
#1 C:\Program Files\Zend\Apache2\htdocs\zf-tutorial\application\controllers\IndexController.php(187): Zend_Db_Table_Row_Abstract->findDependentRowset('Albums')
#2 C:\Program Files\Zend\Apache2\htdocs\zf-tutorial\library\Zend\Controller\Action.php(516): IndexController->editAction()
#3 C:\Program Files\Zend\Apache2\htdocs\zf-tutorial\library\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('editAction')
#4 C:\Program Files\Zend\Apache2\htdocs\zf-tutorial\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#5 C:\Program Files\Zend\Apache2\htdocs\zf-tutorial\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#6 C:\Program Files\Zend\Apache2\htdocs\zf-tutorial\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#7 C:\Program Files\Zend\Apache2\htdocs\zf-tutorial\public\index.php(49): Zend_Application->run()
#8 {main}  

我的相册课程在那里,但不知道为什么它说找不到课程或文件

4

1 回答 1

2

first this is incorrect:

protected $_referenceMap = array(
        'CategoryTypes' => array(
            'columns' => array('category_id'),
            'refTableClass' => 'Category',
            'refColumns' => array('id')
        )
    );

refTableClass needs the whole classname, not the file name:

protected $_referenceMap = array(
        'CategoryTypes' => array(
            'columns' => array('category_id'),
            'refTableClass' => 'Application_Model_DbTable_Category',
            'refColumns' => array('id')
        )
    );

The same holds true for dependentTables:

protected $_dependentTables = array('Application_Model_DbTable_Albums');
}

and make doubly sure that the value of the $_name property always is exactly the same as the name of the table the class represents.

[EDIT]

$category = new Application_Model_DbTable_Category();

$cat_id = $category->find(1);
$cat_3 = $cat_id->current();
//try
$user_cat = $cat_3->findDependentRowset();
//or
$user_cat = $cat_3->findDependentRowset('Application_Model_DbTable_Albums');
//or
$user_cat = $cat_3->findDependentRowset(new Application_Model_DbTable_Albums());
于 2012-08-25T07:13:02.190 回答