zend-frameworkbootstrappingzend-autoloader

Zend autoload not work in bootstrap


i developing a site with zend framework. i use autoload for load a class. it work on controller, on model but not work in bootstrap file. why?

bootstrap.php

   protected function _initAutoload ()
    {
        // Add autoloader empty namespace
        $autoLoader = Zend_Loader_Autoloader::getInstance();
        $resourceLoader = new Zend_Loader_Autoloader_Resource(
                array('basePath' => APPLICATION_PATH, 'namespace' => '',
                        'resourceTypes' => array(
                                'form' => array('path' => 'forms/', 'namespace' => 'Form_'),
                                'model' => array('path' => 'models/', 'namespace' => 'Model_'),
                                'plugin' => array('path' => 'plugin/', 'namespace' => 'Plugin_'))));
        // viene restituto l'oggetto per essere utilizzato e memorizzato nel bootstrap
        return $autoLoader;
    }
    /**
     * inizializza l'autenticazione
     */
    protected function _initAuth ()
    {
        $this->bootstrap("db");
        $this->bootstrap("Autoload");
        $db = $this->getPluginResource('db')->getDbAdapter();
        $adp = new Zend_Auth_Adapter_DbTable($db);
        $adp->setTableName(USERS_TABLE)
        ->setIdentityColumn('username')
        ->setCredentialColumn('password')
        ->setCredentialTreatment('sha1(?)');
        $storage = new Model_Sessions(false, $db);//line 81
        $auth = Zend_Auth::getInstance();
        $auth->setStorage($storage);
        //$this->bootstrap('log');$log=$this->getResource('log');
        if ($auth->hasIdentity()) {
            $identity = $auth->getIdentity();
            $user = $identity->user_id;
        } else
            $user = 1;
        $user = new Model_user($user);
    }

output error

Fatal error: Class 'Model_Sessions' not found in /application/Bootstrap.php on line 81

in Session.php

 <?php
/**
 * @method get($k,$dv=FALSE)
 */
class Model_Sessions implements Zend_Auth_Storage_Interface
{

Solution

  • Your resource autoloader looks good.

    I suspect you want Model_Sessions, not Model_sessions (not lower/upper case on "sessions").

    Make sure the class Model_Sessions is stored in file application/models/Sessions.php

    As a side note, you have your resource autoloader looking for plugins with namespace prefix plugins_. Again, here, I suspect you want uppercase Plugins_.