1

zend フレームワークでサイトを開発しています。クラスをロードするためにオートロードを使用します。コントローラー、モデルでは機能しますが、ブートストラップファイルでは機能しません。なぜ?

ブートストラップ.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);
    }

出力エラー

致命的なエラー: クラス 'Model_Sessions' が /application/Bootstrap.php の 81 行目に見つかりません

Session.php で

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

1 に答える 1

3

リソースオートローダーは良さそうです。

私はあなたが望んModel_Sessionsでいるのではないかと思いますModel_sessions(「セッション」の小文字/大文字ではありません)。

クラスModel_Sessionsがファイルに保存されていることを確認してくださいapplication/models/Sessions.php

補足として、名前空間プレフィックスを持つプラグインを探しているリソースオートローダーがありますplugins_。繰り返しになりますが、ここでは大文字が必要だと思いますPlugins_

于 2013-02-24T02:52:08.060 に答える