2017-08-06 77 views
0

這裏我Module.php:Zend2模塊不能初始化

<?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', 
     ), 
    ), 
); 

但是,當我嘗試查看索引頁,我得到這個:

(!) Fatal error: Uncaught Zend\ModuleManager\Exception\RuntimeException: Module (Users) could not be initialized. in /var/www/html/communicationapp/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php on line 195

(!) Zend\ModuleManager\Exception\RuntimeException: Module (Users) could not be initialized. in /var/www/html/communicationapp/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php on line 195

任何人都知道這段代碼有什麼問題嗎?

回答

0

幾件事情要檢查:

  1. 的文件名是Module.php - 這確切情況。
  2. Module.phpmodule/Users(即不module/Users/src/
+0

是的,文件名是Module.php,它在模塊/ Users 。無論如何,我錯過了我添加到我的composer.json: 「autoload」:{ 「psr-4」:{ 「Application \\」:「module/Application/src /」, 「Users \\」 module/Users/src /「 } } – Salvio

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 /供應商/ zendframework /zend/ModuleManager/Listener/ConfigListener.php(127):Zend \ ModuleManager \ Listener \ ConfigListener-> addConfig('Users',false)

1 [內部函數]:Zend \ ModuleManager \ Listener \ ConfigListener-> onLoadModule(對象(的Zend \ ModuleManager會\ ModuleEvent))

2 /var/www/html/communicationapp/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(444):call_user_func(數組,對象噸(Zend的\ ModuleManager會\ ModuleEvent))

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