2012-08-24 24 views
2

我都有兩個表類相冊和如下類別:Zend_Db_Table類關係的文件或找不到類

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} 

我的相冊類是有,但不知道爲什麼它說找不到類或文件

+0

叫什麼名字和包含'Application_Model_DbTable_Albums'類文件的路徑?它必須是'application/models/DbTable/Alumbs.php'才能被自動加載。 – drew010

+0

是的,這是正確的路徑 – redcoder

回答

2

第一,這是不正確的:

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

refTableClass需要全類名,而不是文件名:

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

同爲dependentTables也是如此:

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

,並加倍確保值$_name屬性的值始終與該類表示的表的名稱完全相同。

[編輯]

$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()); 
+0

這一個可以幫助很多..謝謝RockyFord – redcoder

+0

但是,我如何得到/顯示$ user_cat的結果? – redcoder

+0

檢查編輯。 – RockyFord