首页 文章

Zend2模块无法初始化

提问于
浏览
0

这是我的Module.php:

<?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/ZendSkeletonModule for the canonical source repository
 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace Users;

use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\Mvc\ModuleRouteListener;

class Module implements AutoloaderProviderInterface
{
    public function getAutoloaderConfig()
    {
        return array(
            'Zend\Loader\ClassMapAutoloader' => array(
                __DIR__ . '/autoload_classmap.php',
            ),
            'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(
            // if we're in a namespace deeper than one level we need to fix the \ in the path
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                ),
            ),
        );
    }

    public function getConfig()
    {
        return include __DIR__ . '/config/module.config.php';
    }

    public function onBootstrap($e)
    {
        // You may not need to do this if you're doing it elsewhere in your
        // application
        $eventManager        = $e->getApplication()->getEventManager();
        $moduleRouteListener = new ModuleRouteListener();
        $moduleRouteListener->attach($eventManager);
    }
}

在这里我的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 when developing 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',
        ),
    ),
);

但是当我尝试查看索引页面时,我得到了这个:

(!)致命错误:未捕获Zend \ ModuleManager \ Exception \ RuntimeException:无法初始化模块(用户) . 在第195行的/var/www/html/communicationapp/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php中(!)Zend \ ModuleManager \ Exception \ RuntimeException:模块(用户)无法初始化 . 在第195行的/var/www/html/communicationapp/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php

谁知道这段代码有什么问题?

2 回答

  • 0

    要检查的几件事:

    • 文件名是 Module.php - 确切的情况 .

    • Module.phpmodule/Users (即不在 module/Users/src/ 中)

  • 0

    我使用php的内部服务器,我没有启用xdebug它得到了这个:

    127.0.0.1:48908 [500]:/ public / - 未捕获的Zend \ ModuleManager \ Listener \ Exception \ InvalidArgumentException:要合并的配置必须是数组,实现Traversable接口,或者是Zend \ Config \ Config的实例 . 给定布尔值 . 在/var/www/html/communicationapp/vendor/zendframework/zendframework/library/Zend/ModuleManager/Listener/ConfigListener.php:342堆栈跟踪:

    0 /var/www/html/communicationapp/vendor/zendframework/zendframework/library/Zend/ModuleManager/Listener/ConfigListener.php(127):Zend \ ModuleManager \ Listener \ ConfigListener-> addConfig('Users',false)

    1 [内部函数]:Zend \ ModuleManager \ Listener \ ConfigListener-> onLoadModule(Object(Zend \ ModuleManager \ ModuleEvent))

    2 /var/www/html/communicationapp/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(444):call_user_func(Array,Object(Zend \ ModuleManager \ ModuleEvent))

    3 /var/www/html/communicationapp/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(205):Zend \ EventManager \ EventManager-> triggerListeners(/ var / www / html / communicationapp中的'loadModule)第342行/vendor/zendframework/zendframework/library/Zend/ModuleManager/Listener/ConfigListener.php

相关问题