Search code examples
zend-frameworkautoloader

_initAutoloader database name same as class


I am new at Zend and i am learning. I am getting the following error:

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

But the test tablename is albums in the database, if i change it to model_dbtable_albums it works. I just want to name the table like albums and not the classname.

What do i do wrong ;-)

This is the bootstrap:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap{
    protected function _initAutoload(){
    $moduleloader = new Zend_Application_Module_Autoloader(array(
    'namespace'=> '',  
    'basePath'=> APPLICATION_PATH));

indexAction controller:

public function indexAction()
{
    $albums = new Model_DbTable_Albums();
    $this->view->albums = $albums->fetchAll();
}

Solution

  • Assuming that your model Model_DbTable_Albums extends Zend_Db_Table_Abstract set:

    protected $_name = 'albums';
    

    See the Zend_Db_table docs.