我已经安装了骨架应用程序和工作示例测试骨架应用程序。在我必须在zend骨架应用程序中添加模块结构之后,它显示错误。我的模块名称"相册"。
Module.php
<?php
//testzf2/module/Album/Module.php
namespace Album;
class Album
{
public function getAutoloaderConfig()
{
return array('Zend'Loader'StandardAutoloader' =>
array('namespaces' =>
array(__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,),
),
);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
}
?>
module.config.php
<?php
//testzf2/module/Album/config/module.config.php
return array(
'controllers' => array(
'invokables' => array(
'Album'Controller'Album' => 'Album'Controller'AlbumController', // <----- Module Controller
),
),
// The following section is new and should be added to your file
'router' => array(
'routes' => array(
'album' => array(
'type' => 'segment',
'options' => array(
'route' => '/album[/:action][/:id]', // <---- url format module/action/id
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Album'Controller'Album', // <--- Defined as the module controller
'action' => 'index', // <---- Default action
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'album' => __DIR__ . '/../view',
),
),
);
?>
Albumcontroller.php
<?php
//testzf2/module/Album/src/Album/Controller/AlbumComtroller.php
namespace Album'Controller;
use Zend'Mvc'Controller'AbstractActionController;
class AlbumController extends AbstractActionController
{
public function indexAction()
{
return array('valueA'=>555
,'propertyB'=>888);
}
}
?>
我收到错误:
Fatal error: Uncaught exception 'Zend'ModuleManager'Exception'RuntimeException' with message 'Module (Application) could not be initialized.' in D:'xampp'htdocs'Zend'vendor'zendframework'zendframework'library'Zend'ModuleManager'ModuleManager.php:195 Stack trace: #0 D:'xampp'htdocs'Zend'vendor'zendframework'zendframework'library'Zend'ModuleManager'ModuleManager.php(169): Zend'ModuleManager'ModuleManager->loadModuleByName(Object(Zend'ModuleManager'ModuleEvent)) #1 D:'xampp'htdocs'Zend'vendor'zendframework'zendframework'library'Zend'ModuleManager'ModuleManager.php(96): Zend'ModuleManager'ModuleManager->loadModule('Application') #2 [internal function]: Zend'ModuleManager'ModuleManager->onLoadModules(Object(Zend'ModuleManager'ModuleEvent)) #3 D:'xampp'htdocs'Zend'vendor'zendframework'zendframework'library'Zend'EventManager'EventManager.php(468): call_user_func(Array, Object(Zend'ModuleManager'ModuleEvent)) #4 D:'xampp'htdocs'Zend'vendor'zendframework'zendframework'library'Zend'EventManager'EventManager.php(207): Zend'EventMana in D:'xampp'htdocs'Zend'vendor'zendframework'zendframework'library'Zend'ModuleManager'ModuleManager.php on line 195
错误消息显示:
无法初始化模块(应用程序)。
所以它讨厌与你的相册模块无关!我认为您的config/application.config.php路径错误和/或Module.php/config.Module.php在application 中不正确
您的Module.php
签名不符合PSR自动加载标准,ZF2的模块自动加载程序无法初始化您的模块。
尝试从更改类名Album
<?php
namespace Album;
class Album
{
至
<?php
namespace Album;
class Module
{
这应该行得通。