2012-01-06 33 views
0

我遇到的關於改變默認的表名問題

class Application_Model_DbTable_Game extends Zend_Db_Table_Abstract 
{ 

protected $_name = 'games'; 

錯誤:

消息:SQLSTATE [42S02]:基表或視圖未找到:1146表「gamenomad_dev.game '不存在

幫幫我...它應該很簡單!

*編輯 這裏的問題是,Zend Framework應該檢測從默認的'遊戲'到'遊戲'的變化表名稱。

+0

向我們展示了問題實際所在的路線。和完整的錯誤消息。 – redmoon7777 2012-01-06 06:39:47

+0

向我們展示您的查詢btw – redmoon7777 2012-01-06 06:40:22

+0

您必須自己創建表(使用'CREATE TABLE games(...'),'Zend_Db'-組件不會自動創建表。表被稱爲'遊戲',在DbTable中它是'遊戲'哪一個是正確的? – vstm 2012-01-06 06:41:06

回答

0

在ZF中,您必須硬編碼您的數據庫表進行建模。它不掃描數據庫更改。你有兩種方式:

創建一個表名類

class Game extends Zend_Db_Table_Abstract 
{ 
    // default table name: game 
} 

如果你想使用ZF的默認路徑,你應該把DBTABLE模型爲application/models/dbtable目錄和樣Application_Model_DbTable_Game命名類 - 那麼ZF知道它必須尋找game

創建類的任何名稱

例如ExtraGameTable並設置其參數顯示錶名:

class ExtraGameTable extends Zend_Db_Table_Abstract 
{ 
    protected $_name = 'game'; 
} 

正如文件指出:http://framework.zend.com/manual/en/zend.db.table.html

If you don't specify the table name, it defaults to the name of the class. If you rely on this default, the class name must match the spelling of the table name as it appears in the database.

您可以嘗試將其與一些配置文件和負載表的名字從那裏合併,但仍 - ZF不會知道任何有關底層數據庫更改的信息。

0

顯示實際的行和堆棧跟蹤到您的問題,也許你正在生成你的查詢,它不讀取實際的表名稱。

相關問題