我已经安装了Zend框架。它的工作演示页面。安装模块后,它没有打开显示错误。
RuntimeException' with message 'Module (Users) could not be initialized.'
D:xampphtdocsCommunicationAppvendorzendframeworkzendframeworklibraryZendModuleManagerModuleManager.php:195 Stack trace: #0 D:xampphtdocsCommunicationAppvendorzendframeworkzendframeworklibraryZendModuleManagerModuleManager.php(169): ZendModuleManagerModuleManager->loadModuleByName(Object(ZendModuleManagerModuleEvent)) #1 D:xampphtdocsCommunicationAppvendorzendframeworkzendframeworklibraryZendModuleManagerModuleManager.php(96): ZendModuleManagerModuleManager->loadModule('Users') #2 [internal function]: ZendModuleManagerModuleManager->onLoadModules(Object(ZendModuleManagerModuleEvent)) #3 D:xampphtdocsCommunicationAppvendorzendframeworkzendframeworklibraryZendEventManagerEventManager.php(468): call_user_func(Array, Object(ZendModuleManagerModuleEvent)) #4 D:xampphtdocsCommunicationAppvendorzendframeworkzendframeworklibraryZendEv in
module.config.php
<?php
return array(
'controllers' => array(
'invokables' => array(
'UsersControllerIndex' => 'UsersControllerIndexController',
),
),
'router' => array(
'routes' => array(
'users' => array( 'type' => 'Literal',
'options' => array(
// Change this to something specific to your module
'route' => '/users',
'defaults' => array(
// Change this value to reflect the namespace in which
// the controllers for your module are found
'__NAMESPACE__' => 'UsersController',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
// This route is a sane default whendeveloping a module;
// as you solidify the routes for your module,however,
// you may want to remove it and replace it with more
// specific routes.
'default' => array(
'type' => 'Segment',
'options' => array(
'route' =>'/[:controller[/:action]]',
'constraints' => array(
'controller' =>'[a-zA-Z][a-zA-Z0-9_-]*',
'action' =>'[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'users' => __DIR__ . '/../view',
),
),
);
Module.php
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Application;
use ZendMvcModuleRouteListener;
use ZendMvcMvcEvent;
class Module
{
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getAutoloaderConfig()
{
return array(
'ZendLoaderStandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
}
Module.php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Application;
use ZendMvcModuleRouteListener;
use ZendMvcMvcEvent;
class Module
{
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getAutoloaderConfig()
{
return array(
'ZendLoaderStandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
}
我不知道我错在哪里了。安装骨架Zend应用程序后运行良好。安装模块后显示错误。我的模块名称"用户"
在Application和User模块的module.php类中都有Application命名空间声明。这似乎有问题。(我不知道你的目录脚手架,你是否正确地将模块分离到正确的目录中?)
每个模块应该分别具有不同的名称空间。作为第一步,您应该从更改User模块的名称空间声明
namespace Application;
至
namespace User;
您可能还想阅读一些关于PHP命名空间的文档。