我有一个测试模块。
我在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类?
感谢
您应该能够通过以下方式在测试模块引导类(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;
}
}
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_' )
)
));
}
它现在正在工作。