Zend framework2 Zend Framework 2类映射自动加载程序错误
我对Zend Framework 2非常陌生,我使用Michael Romer的《Zend Framework 2的Web开发》一书作为我的指南。我在第5章的末尾介绍了ClassMapAutoloader的主题。讨论的结论是,我的Helloworld模块现在的文件和目录结构为->Zend framework2 Zend Framework 2类映射自动加载程序错误,zend-framework2,Zend Framework2,我对Zend Framework 2非常陌生,我使用Michael Romer的《Zend Framework 2的Web开发》一书作为我的指南。我在第5章的末尾介绍了ClassMapAutoloader的主题。讨论的结论是,我的Helloworld模块现在的文件和目录结构为-> Module.php autoload_classmap.php autoload_function.php autoload_register.php config/ module.config.php p
Module.php
autoload_classmap.php
autoload_function.php
autoload_register.php
config/
module.config.php
public/
images/
css/
js/
src/
Helloworld/
Controller/
IndexController.php
views/
Helloworld/
Index/
index.phtml
据我所知,setup Classmap autoloading感兴趣的文件有Module.php、autoload_Classmap.php、autoload_function.php、autoload_register.php。这些文件的内容是
Module.php->
<?php
namespace Helloworld;
Class Module {
public function getAutoloaderConfig() {
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php'
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__
)
)
);
}
public function getConfig() {
return include __DIR__ . '/config/module.config.php';
}
}
类映射文件中不需要自动加载程序注册函数。就是
您可以使用Zend Framework 2中提供的生成autoloader类映射。您可以生成autoload_classmap.php
文件,以便使用模块中的所有php类填充该文件
用法:
$ cd module/MyModule
$ ../../vendor/zendframework/zendframework/bin/classmap_generator.php -w
这适用于使用composer加载Zend Framework 2的情况,composer将加载供应商/
目录中的库。在Module.php中的name之后添加两行代码
namespace Helloworld;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
错误是什么?你能复制/粘贴吗?艾迪,伍普西,忘了错误。我编辑了我原来的帖子,现在就把它收录进去了。谢谢你的帮助。啊。。。我明白了。自动加载的_classmap.php由.././vendor/zendframework/zendframework/bin/classmap_generator.php-w从命令行生成。然后是autoload_function.php和autoload_register.php使生成的autoload_classmap.php文件对我的模块有用。
<?php
//require_once 'autoload_register.php';
return array();
$ cd module/MyModule
$ ../../vendor/zendframework/zendframework/bin/classmap_generator.php -w
namespace Helloworld;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;