2012-06-06 113 views
0

在方法checkUnique中執行以下類中的行$res=$select->fetchArray();我得到一個我無法解決的錯誤。zend教條找不到類

我認爲這是由於命名約定的Zend自動加載

class Twit_Model_Owners extends Twit_Model_BaseOwners { 

    function checkUnique($username) { 
     $con = Doctrine_Manager::getInstance()->connection(); 
     $select = $con->createQuery(); 
     $select->from($this->getTable()->getTableName(), array('loginName')) 
       ->where('loginName=?', $username); 
     $res=$select->fetchArray(); 

     if (empty($res)) { 
      return true; 
     } 
     return false; 
    } 
} 

例外:

Application error 

Exception information: 

Message: Couldn't find class Owners 
Stack trace: 

#0 /usr/share/php/Doctrine/lib/Doctrine/Table.php(256): Doctrine_Table->initDefinition() 
#1 /usr/share/php/Doctrine/lib/Doctrine/Connection.php(1126): Doctrine_Table->__construct('Owners', Object(Doctrine_Connection_Mysql), true) 
#2 /usr/share/php/Doctrine/lib/Doctrine/Query.php(1942): Doctrine_Connection->getTable('Owners') 
#3 /usr/share/php/Doctrine/lib/Doctrine/Query.php(1740): Doctrine_Query->loadRoot('Owners', 'Owners') 
#4 /usr/share/php/Doctrine/lib/Doctrine/Query/From.php(88): Doctrine_Query->load('Owners') 
#5 /usr/share/php/Doctrine/lib/Doctrine/Query/Abstract.php(2077): Doctrine_Query_From->parse('Owners') 
#6 /usr/share/php/Doctrine/lib/Doctrine/Query.php(1167): Doctrine_Query_Abstract->_processDqlQueryPart('from', Array) 
#7 /usr/share/php/Doctrine/lib/Doctrine/Query.php(1133): Doctrine_Query->buildSqlQuery(true) 
#8 /usr/share/php/Doctrine/lib/Doctrine/Query/Abstract.php(958): Doctrine_Query->getSqlQuery(Array) 
#9 /usr/share/php/Doctrine/lib/Doctrine/Query/Abstract.php(1026): Doctrine_Query_Abstract->_execute(Array) 
#10 /usr/share/php/Doctrine/lib/Doctrine/Query.php(267): Doctrine_Query_Abstract->execute(Array, 3) 
#11 /var/www/twit/application/models/Owners.php(20): Doctrine_Query->fetchArray() 
#12 /var/www/twit/application/controllers/AuthController.php(62): Twit_Model_Owners->checkUnique('a') 
#13 /usr/share/php/libzend-framework-php/Zend/Controller/Action.php(516): AuthController->signupAction() 
#14 /usr/share/php/libzend-framework-php/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('signupAction') 
#15 /usr/share/php/libzend-framework-php/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) 
#16 /usr/share/php/libzend-framework-php/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch() 
#17 /usr/share/php/libzend-framework-php/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run() 
#18 /var/www/twit/public/index.php(30): Zend_Application->run() 
#19 {main} 

Request Parameters: 

array (
    'module' => 'default', 
    'controller' => 'auth', 
    'action' => 'signup', 
    'username' => 'a', 
    'password' => 'x', 
    'confirmPassword' => 'x', 
    'captcha' => 
    array (
    'id' => 'ae5e3ce58bcf69e25ccdbba601029325', 
    'input' => 'hen753', 
), 
    'register' => 'Sign up', 
) 

我可以實例化的模型沒有問題。這是我用它來生成模型代碼:

Doctrine::generateModelsFromDb('/var/www/twit/application/models', array('zenddb'), array(
      'baseClassesDirectory' => '', 
      'classPrefix' => 'Twit_Model_', 
      'classPrefixFiles' => false 
      )); 

此外,如果你願意,你可以點擊這裏查看示例頁面,在這裏自己得到的錯誤。

http://94.94.19.135/twit/public/index.php/signup 

回答

0

似乎主義並不想表的名稱,由$this->getTable()->getTableName() 爲返回,但對象的名稱(在我的情況Twit_Model_Owners) 我個人無法理解這樣的選擇(抽象是確定的,但至少查詢生成器中的表的名稱應該被修補),但我抱怨。