2
votes

I am trying to learn Zend framework from "Getting Started with Zend Framework" By Rob Allen. I have used the same example that has been given, but getting the error -

Fatal error: Class 'Application_Model_DbTable_Albums' not found in /var/www/html/workbench/sreekantk/zf-tutorial/application/controllers/IndexController.php on line 14 .

I think I have to set path to models folder, but don't know how to do it. Could anyone please help me out of this.

This is my Bootstrap.php file.

// application/Bootstrap.php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
    {
    protected function _initAutoload()
    {
        $autoloader = new Zend_Application_Module_Autoloader(array(
            'namespace' => '',
            'basePath'  => APPLICATION_PATH.'/application/modules'));
        return $autoloader;
    }

}

Thanks Just H. It worked. Actually I changed the folder structure and after the again added appnamespace="Application" to the application.ini file. Thanks you all for your comments.

4
Could you let us know the folder structure of where your model Class file is, and how you have setup autoloading for your models.ChrisA
Have you pasted the "Zend Library" to /library folder of your application...?Pushpendra
Perhaps check your application.ini. I think you want to have the following set: appnamespace = Application and then make sure your models are in the application/models directory.H Hatfield
@Just H: I have done that too.user556773
@Chris : I have included my Bootstrap file.user556773

4 Answers

2
votes

As long as you get to the controller your primary setup seems to be fine. So, if you have the class in a separate file the problem is probably a simple typo somewhere.

a) with all the following, look out for lower/upper case
b) note that the models folder is plural whereas the class is Model singular
c) make sure the class is named Application_Model_DbTable_Albums
d) make sure the file is named Albums.php and in a folder named application/models/DbTable

Good luck learning ZF

1
votes

Since version 1.9.2, the default module will automatically initialise an autoloader for the namespace configured in appnamespace (defaults to "Application" on a vanilla install). You can remove your _initAutoload() method.

So long as your class exists in application/models/DbTable/Albums.php and is named Application_Model_DbTable_Albums, it should be able to autoload the class on first use.

Be mindful of path case sensitivity.

0
votes

I'm following the same tutorial and what Adrian World said on Aug 9'11 at 13:26 helped me get rid of the error. My Bootstrap now is:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initAutoload()
    {
        $autoloader = new Zend_Application_Module_Autoloader(array(
            'namespace' => '',
            'basePath'  => APPLICATION_PATH.'/application/models'));
        return $autoloader;
    }
}

Where the only thing that changed was going from modules to models

0
votes

You should define Bootstrap class of the current Module. Then it will be fine.