【问题标题】:Zend autoload not work in bootstrapZend 自动加载在引导程序中不起作用
【发布时间】:2013-02-23 20:50:37
【问题描述】:

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

输出错误

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

在 Session.php 中

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

【问题讨论】:

    标签: zend-framework bootstrapping zend-autoloader


    【解决方案1】:

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

    我怀疑你想要Model_Sessions,而不是Model_sessions(“会话”上不是小写/大写)。

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

    附带说明,您的资源自动加载器正在寻找具有命名空间前缀plugins_ 的插件。同样,在这里,我怀疑你想要大写的Plugins_

    【讨论】:

      猜你喜欢
      • 2017-06-14
      • 1970-01-01
      • 2016-03-26
      • 2023-03-27
      • 2014-02-15
      • 1970-01-01
      • 2011-03-18
      • 2021-09-03
      • 2017-04-11
      相关资源
      最近更新 更多