2011-06-05 20 views
1

我有一個測試模塊。如何在Zend中爲模塊添加資源?

我在的myproject /應用/模塊/測試/列表一類/ Profiles.php

class Test_List_Profiles { 
    // class members  
} 

現在,當我在的myproject /應用/模塊/測試/控制器訪問該類/ 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類無處不在的項目?

感謝

+0

很多錯別字固定.. – Student 2011-06-05 06:45:34

+0

其中Notification_List_Notifications是在哪裏定義的? – 2011-06-05 06:46:37

+0

@zeeshan:拼寫錯誤。請再次檢查問題。 – Student 2011-06-05 07:16:04

回答

4

你應該能夠增加您的列表中資源的測試模塊引導類(myproject的/應用/模塊/測試/ 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; 

    } 

} 
+0

是的你是對的。這也是一種方式,但我也在我的bootstrap.php中找到了我的錯誤。檢查我的答案以及。謝謝。 – Student 2011-06-05 12:07:05

0

有錯誤在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_') 
            ) 
     ));   
} 

它現在正在工作。

相關問題