Question

I've this issue on my project and i don't know what more i can do to solve it.

On my localhost enviroment it's work just fine, but when i send it to server simply stop work with this waring+fatal error menssage.

Warning: include_once(model/Login.php): failed to open stream:
 No such file or directory in /var/www/ecommerce/include_path/Zend/Loader.php on line 134 Warning: include_once(): 
Failed opening 'model/Login.php' for inclusion 
(include_path='/var/www/wdna.com.br/admin2/application/../library::/var/www/wdna.com.br/admin2/library:
/var/www/wdna.com.br/admin2/application/modules.:/usr/share/php:/var/www/ecommerce/include_path') in /var/www/ecommerce/include_path/Zend/Loader.php on line 134 
Fatal error: Class 'model_Login' not found in /var/www/wdna.com.br/admin2/application/modules/default/controllers/LoginController.php on line 15

My folder structure is something like that:

+---application
|   \---modules      
|       \---default
|           +---models

LoginController.php:

15        $login = new default_models_Login();
16        $login = $login->login($this->_getParam('login'), $this->_getParam('senha'));

My function _initAutoloader:

protected function _initAutoloader(){        
        $autoloader = Zend_Loader_Autoloader::getInstance();
        $autoloader->registerNamespace('App');                
    }

The new error:

Warning: include_once(Default/Models/Login.php): failed to open stream: No such file or directory in /var/www/ecommerce/include_path/Zend/Loader.php on line 134 Warning: include_once(): Failed opening 'Default/Models/Login.php' for inclusion (include_path='/var/www/wdna.com.br/admin2/application/../library::/var/www/wdna.com.br/admin2/library:/var/www/wdna.com.br/admin2/application/modules.:/usr/share/php:/var/www/ecommerce/include_path') in /var/www/ecommerce/include_path/Zend/Loader.php on line 134 Fatal error: Class 'Default_Models_Login' not found in /var/www/wdna.com.br/admin2/application/modules/default/controllers/LoginController.php on line 15

Any help will be much appreciated.

Was it helpful?

Solution 3

The solution is create a new autoloader

example:

class MyLib_Autoloader implements Zend_Loader_Autoloader_Interface
{
    public function autoload($class)
    {

        $include = str_replace('_', DIRECTORY_SEPARATOR, $class);
        $folder = explode(DIRECTORY_SEPARATOR, $include);
        if(in_array($folder[0], array('default', 'cep', 'boleto')))
            require_once '..\..\application\modules\\' .  $include . '.php';
        else
            require_once $include . '.php';
        return $class;
    }

}

end call in Bootstrap.php:

protected function _initAutoloading()
{
    $autoloader = Zend_Loader_Autoloader::getInstance();
    $autoloader->pushAutoloader(new MyLib_Autoloader());
}

the "else" are to call to a class that are not in modules and the array are the modules that i created.

OTHER TIPS

I've had this issue before and it turned out to be a typo. On Windows and OSX it doesn't really care if your file names are in the correct case (for the most part) but in a Linux environment its much more strict.

Even if you believe that your filenames follow the correct case make sure that your class names do as well this is where I found my typo to be hiding.

You class should look something like this:

class Default_Model_Login {
}

Though this could give you a conflict as 'Default' is the default model for the Zend and not displayed as a model but as the main application which is why a lot of classes start with Default_

Hope this helps.

The autoloader is case-sensitive (on Linux), so you need to use the same case for your class name wherever you use it. In your controller, you should have:

$login = new Default_Models_Login();

and your class should be defined as:

class Default_Models_Login

(note the capital 'D' and 'M' in both cases).

You also have your library folder on the include path twice (the first two paths listed are equivalent), so you might want to fix that too.

Edit: Apologies, I gave you some bad info. The standard autoloader (what you're using), expects to be able to find classes on the file system based on their class name only. Since it's case-sensitive on Linux, to fix your problem you would need to also change your default folder to Default, and models to Models. But this is likely to break other things. The standard autoloader is not designed for autoloading classes in the application folder for this reason.

The best solution, assuming you want to stick with ZF conventions would be to use ZF's module autoloader (which is specifically designed for classes inside application/modules). To do this, you need to:

Create a bootstrap file for your module. This file should live at application/modules/default/Bootstrap.php and contain:

class Default_Bootstrap extends Zend_Application_Module_Bootstrap
{

}

You might also need to init the module resource by adding:

resources.modules[] =

to your application.ini file.

This should setup the module autoloader for your default module. The module autoloader sets up a number of different resources by default (see the docs: http://framework.zend.com/manual/1.12/en/zend.loader.autoloader-resource.html#zend.loader.autoloader-resource.module), including one for models. However the default assumes your class name will use the word Model rather than Models. So you'll also need to change your class name to Default_Model_Login (but leave the folder name as models). Hopefully then it should all work!

All of this is about a 100 times easier in ZF2.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top