2012-01-06 43 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

显示实际的行和堆栈跟踪到您的问题,也许你正在生成你的查询,它不读取实际的表名称。