Autoloading of class in MVC Zend Framework doesnt work
I finished my first web application in MVC zend framework and everything works great on my localhost.
So I upload it on server and there is problem with autoloading my class. I get error message when i wanna create object from my class in indexcontroller:
$this->view->bottomCache = new Application_Model_Cache($this->cacheTime,'bottomCache');
And i get this err msg:
Fatal error: Class 'Application_Model_Cache' not found in ........./IndexController.php on line 19
On my localhost I am using Zend Server CE and there it works.
Please, can you give me some advices, what i would check to get know why it doesnt work?
SOLVED: first letter of name of class has to be uppercase, Cache.php
EDIT2: Folder models vs. model As you can see in this example
// application/models/Guestbook.php class Application_Model_Guestbook {
EDIT1: I used tutorial on http://framework.zend.com/manual/en/learning.quickstart.create-project.html, so i used file structure which is there.
quickstart |-- application | |-- Bootstrap.php | |-- configs | | `-- application.ini | |-- controllers | | |-- ErrorController.php | | `-- IndexControl开发者_如何学编程ler.php | |-- models | | |-- cache.php | | `-- DbTable | | `-- Downloaded.php | `-- views | |-- helpers | `-- scripts | |-- error | | `-- error.phtml | `-- index | `-- index.phtml |-- library |-- public | |-- .htaccess | `-- index.php
Bootstrap.php In my boot strap i have got:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { protected function _initAutoload() { $autoloader = new Zend_Application_Module_Autoloader(array( 'namespace' => 'Application_', 'basePath' => dirname(__FILE__), ));; $autoloader->addResourceType('model', 'model/', 'Model'); return $autoloader; } protected function _initDoctype() { $this->bootstrap('view'); $view = $this->getResource('view'); $view->doctype('XHTML1_TRANSITIONAL'); } }
application.ini
[production] phpSettings.display_startup_errors = 0 phpSettings.display_errors = 0 includePaths.library = APPLICATION_PATH "/../library" bootstrap.path = APPLICATION_PATH "/Bootstrap.php" bootstrap.class = "Bootstrap" appnamespace = "Application" resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers" resources.frontController.params.displayExceptions = 0 resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/" phpSettings.date.timezone = "Europe/London" resources.db.adapter = PDO_MYSQL resources.db.params.host = localhost resources.db.params.username = ***** resources.db.params.password = **** resources.db.params.dbname = ***** resources.db.params.charset = "utf8" resources.db.params.names = "utf8" resources.view.doctype = "XHTML1_TRANSITIONAL" [staging : production] [testing : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 [development : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 resources.frontController.params.displayExceptions = 1
Edit2: You have to call your cache.php file Cache.php. Its case sesnsitive. Try that.
Edit: in your structure its a Models (see that s) folder. You invoke the class with
Application_Model_Cache
So ZF is looking for it in application/model/.
So change your class to
Application_Models_Cache
Don`t forget to do it inside the classes code. Or change the folder name to models (seems all your code references models so changing the folder seems the quickest way.
Your class is Application_Model_Cache which should be found on ./application/models where the file name should be Cache.php.
精彩评论