运行时异常';带有消息';无法初始化模块(用户)';


RuntimeException' with message 'Module (Users) could not be initialized.'

我已经安装了Zend框架。它的工作演示页面。安装模块后,它没有打开显示错误。

 RuntimeException' with message 'Module (Users) could not be initialized.'
D:'xampp'htdocs'CommunicationApp'vendor'zendframework'zendframework'library'Zend'ModuleManager'ModuleManager.php:195 Stack trace: #0 D:'xampp'htdocs'CommunicationApp'vendor'zendframework'zendframework'library'Zend'ModuleManager'ModuleManager.php(169): Zend'ModuleManager'ModuleManager->loadModuleByName(Object(Zend'ModuleManager'ModuleEvent)) #1 D:'xampp'htdocs'CommunicationApp'vendor'zendframework'zendframework'library'Zend'ModuleManager'ModuleManager.php(96): Zend'ModuleManager'ModuleManager->loadModule('Users') #2 [internal function]: Zend'ModuleManager'ModuleManager->onLoadModules(Object(Zend'ModuleManager'ModuleEvent)) #3 D:'xampp'htdocs'CommunicationApp'vendor'zendframework'zendframework'library'Zend'EventManager'EventManager.php(468): call_user_func(Array, Object(Zend'ModuleManager'ModuleEvent)) #4 D:'xampp'htdocs'CommunicationApp'vendor'zendframework'zendframework'library'Zend'Ev in

module.config.php

 <?php
return array(
'controllers' => array(
'invokables' => array(
'Users'Controller'Index' => 'Users'Controller'IndexController',
),
),
'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__' => 'Users'Controller',
'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 Zend'Mvc'ModuleRouteListener;
use Zend'Mvc'MvcEvent;
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(
            'Zend'Loader'StandardAutoloader' => 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 Zend'Mvc'ModuleRouteListener;
use Zend'Mvc'MvcEvent;
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(
            'Zend'Loader'StandardAutoloader' => array(
                'namespaces' => array(
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                ),
            ),
        );
    }
}

我不知道我错在哪里了。安装骨架Zend应用程序后运行良好。安装模块后显示错误。我的模块名称"用户"

ApplicationUser模块的module.php类中都有Application命名空间声明。这似乎有问题。(我不知道你的目录脚手架,你是否正确地将模块分离到正确的目录中?)

每个模块应该分别具有不同的名称空间。作为第一步,您应该从更改User模块的名称空间声明

namespace Application;

namespace User;

您可能还想阅读一些关于PHP命名空间的文档。