0

I encountered a problem regarding changing default table name

class Application_Model_DbTable_Game extends Zend_Db_Table_Abstract
{

protected $_name = 'games';

Error:

Message: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'gamenomad_dev.game' doesn't exist

Help me... it's supposed to be simple!

*EDIT The problem here is that Zend Framework is supposed to detect the changed table name from the default 'game' into 'games'.

shiva8
  • 2,142
  • 2
  • 19
  • 24
  • show us the line where the problem actually is. and the full error msg. – redmoon7777 Jan 06 '12 at 06:39
  • Well you have to create the table yourself (with `CREATE TABLE games (...`), the `Zend_Db`-components do not create the tables automatically. Edit: Btw in the error message the table is called `game` and in DbTable it's `games` which one is correct? – vstm Jan 06 '12 at 06:41
  • The problem is that Zend Framework supposed to detect the change $_name so that it doesn't look for the default table name 'game' but instead the changed table name 'games'. And the table 'games' does exist. – shiva8 Jan 06 '12 at 06:49

2 Answers2

0

In ZF you have to hardcode your database table to model. It doesn't scan for database changes. You have two ways:

Create class with table name

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

If you want to use ZF's default paths, you should put DBTable model into application/models/dbtable directory and name your class like Application_Model_DbTable_Game - then ZF knows it has to look for game table

Create class with any name

e.g. ExtraGameTable and set its parameters to show table name:

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

As stated in documentation: 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.

You may try to combine it with some configuration file and load table names from there, but still - ZF won't know anything about underlying database changes.

BartekR
  • 3,827
  • 3
  • 24
  • 33
0

Show the actual line and stacktrace to your problem, maybe you are generating your query in a way it doesn't read the actual table name.

Chris
  • 884
  • 5
  • 8