Zend自动加载在引导程序中不起作用



i使用zend框架开发一个站点。我使用自动加载来加载类。它适用于控制器、模型,但不适用于引导文件。为什么?

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);
    }

输出错误

致命错误:在/application/Bootstrap.php的第81行中找不到类"Model_Sessions"

在Session.php 中

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

您的资源自动加载器看起来不错。

我怀疑您想要的是Model_Sessions,而不是Model_sessions(在"sessions"中不是小写/大写)。

确保类Model_Sessions存储在文件application/models/Sessions.php

附带说明一下,您的资源自动加载器正在查找名称空间前缀为plugins_的插件。同样,在这里,我怀疑您想要大写的Plugins_

最新更新