我已经安装了骨架应用程序和工作样本测试骨架应用程序。之后我必须在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
答案 0 :(得分:0)
错误消息显示:
模块(应用程序)无法初始化。
所以它不喜欢你的专辑模块! 我认为您的config / application.config.php有错误的路径和/或您的Module.php / config.module.php在应用程序中不正确
答案 1 :(得分:0)
您的Module.php
签名并不尊重PSR autoloading standard,而ZF2 Module Autoloader无法初始化您的模块。
尝试从
更改类名Album
<?php
namespace Album;
class Album
{
到
<?php
namespace Album;
class Module
{
这应该有用。