views:

45

answers:

1

Hello, 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 big, 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
|   |   `-- IndexController.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

+1  A: 

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.

Iznogood
I added _initAutoload, but the problem is still same. I am using file structure like in quickstart tutorial on framework.zend.com.
312k1t
@312k1t Edited my answer. You use models in your class but have a model folder. They have to mach for autoloader to work.
Iznogood
I dont know why, but this is not the problem. This works on my localhost and it is in tutorials too. It was one of the first thing what i changed but it still doesnt work.
312k1t
@312k1t So the file structure you posted was`nt the real one? Because what I am seeing in your question is clearly A problem. Maybe not THE problem but it will not work like that. SO fix the question with relevent real as is code and I will try again to help.
Iznogood
The class Application_Model_Cache is in application/models/cache.php, i tried to rename folder models to model, but the problem is still same.
312k1t
@312k1t Ill say it one last time. Zend's autoloader uses the name of the class to find it in yoru structure. It has to match. Regardless of if it works after. Ill create a project with your code and try to see whats wrong. I hope to God the code in your question is the same as your real code because I will use that to test against.
Iznogood
@Just had a flash. How do you call your cache class inside cache.php? How about you post that too in your question so I am sure nothing is wrong in there.
Iznogood
@312k1t you have to call your cache.php file Cache.php. Its case sesnsitive. Try that.
Iznogood
Thanx, that was the problem. I made it under windows, so there it worked. On unix server not. Thank You
312k1t
@312k1t dont forget to upvote and accept answers to motivate others to help you in the future :) Happy to have helped!
Iznogood