【问题标题】:How to add resource for module in Zend?如何在 Zend 中为模块添加资源?
【发布时间】:2011-06-05 06:40:04
【问题描述】:

我有一个测试模块。

我在 myproject/application/modules/test/lists/Profiles.php 中有一个类

class Test_List_Profiles {
    // class members    
} 

现在当我在 myproject/application/modules/test/controllers/ProfileController.php

中访问此类时
public function indexAction() {
   $profilesList = new Test_List_Profiles();
}

它给了我以下错误:

Fatal error: Class 'Test_List_Profiles' not found 

我在 Bootstrap.php 中也有以下条目:

protected function _initAutoload() {

  $autoLoader = Zend_Loader_Autoloader::getInstance();

  $testModuleLoader = new Zend_Loader_Autoloader_Resource(array(
            'basePath' => APPLICATION_PATH . 'modules/test',
            'namespace' => 'Test_',
            'resourceTypes' => array( 'form' => array( 'path'=>'forms/', 'namespace'=>'Form_' ),
                                      'list' => array( 'path'=>'lists/', 'namespace'=>'List_' )  
                                    )
        ));           
}

如何在项目中随处访问 Test_List_Profiles 类?

谢谢

【问题讨论】:

  • Notification_List_Notifications 是在哪里定义的?
  • @zeeshan:这是拼写错误。请再次查看问题..

标签: php zend-framework module bootstrapping


【解决方案1】:

您应该可以通过这种方式在测试模块引导类 (myproject/application/modules/test/Bootstrap.php) 中添加您的列表资源:

class Test_Bootstrap extends Zend_Application_Module_Bootstrap {

    protected function _initAutoload(){

        $autoloader = $this->getResourceLoader();

        $autoloader->addResourceType('list', 'models/lists', 'Model_List');

        return $autoloader;

    }

}

【讨论】:

  • 是的,你是对的。这也是一种方法,但我在 bootstrap.php 中也发现了我的错误。也看看我的回答。谢谢。
【解决方案2】:

basePath 路径有错误。缺少斜线 (/)。

protected function _initAutoload() {

  $autoLoader = Zend_Loader_Autoloader::getInstance();

  $testModuleLoader = new Zend_Loader_Autoloader_Resource(array(
            'basePath' => APPLICATION_PATH . '/modules/test',
            'namespace' => 'Test_',
            'resourceTypes' => array( 'form' => array( 'path'=>'forms/', 'namespace'=>'Form_' ),
                                      'list' => array( 'path'=>'lists/', 'namespace'=>'List_' )  
                                    )
        ));           
}

它现在正在工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-28
    • 1970-01-01
    • 2012-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多