ZF 2: tutorial application, 'Config being merged must be an array […]'

 ̄綄美尐妖づ 提交于 2019-12-23 21:28:00

问题


My Enviroment (Zend Server):

PHP Version 5.4.11
Zend Server Version: 6.0.1
Zend Framework: 1.12.3, 2.1.4
Zend Server Gateway: 0.9.0.201301302347
Build: 69400

So I tried to write my first application in ZF2 form official tutorial.

ZF version in skeleton application: 2.2

This is link to my project, if someone wants to look at it closer.

config/module.config.php

<?php
return array(
    'controllers' => array(
        'invokables' => array(
            'Album\Controller\Album' => 'Album\Controller\AlbumController',
        ),
    ),
    'view_manager' => array(
        'template_path_stack' => array(
            'album' => __DIR__ . '/../view',
        ),
    ),
);

module\Album\Module.php

<?php
namespace Album;

class Module
{
    public function getAutoloaderConfig()
    {
        return array(
            'Zend\Loader\ClassMapAutoloader' => array(
                __DIR__ . '/autoload_classmap.php',
            ),
            'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                ),
            ),
        );
    }

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

And this is my error:

Zend\ModuleManager\Listener\Exception\InvalidArgumentException: Config being merged must be an array, implement the Traversable interface, or be an instance of Zend\Config\Config. integer given. in F:\Zend\Apache2\htdocs\learnzf2\vendor\zendframework\zendframework\library\Zend\ModuleManager\Listener\ConfigListener.php on line 317
Call Stack
#   Time    Memory  Function    Location
1   1.0510  137456  {main}( )   ..\index.php:0
2   1.0986  163240  Zend\Mvc\Application::init( )   ..\index.php:18
3   1.2171  345520  Zend\ModuleManager\ModuleManager->loadModules( )    ..\Application.php:253
4   1.2171  345680  Zend\EventManager\EventManager->trigger( )  ..\ModuleManager.php:109
5   1.2171  345936  Zend\EventManager\EventManager->triggerListeners( ) ..\EventManager.php:207
6   1.2195  354296  call_user_func ( )  ..\EventManager.php:468
7   1.2195  354312  Zend\ModuleManager\ModuleManager->onLoadModules( )  ..\EventManager.php:468
8   1.2371  383920  Zend\ModuleManager\ModuleManager->loadModule( ) ..\ModuleManager.php:90
9   1.2390  384984  Zend\EventManager\EventManager->trigger( )  ..\ModuleManager.php:154
10  1.2391  385016  Zend\EventManager\EventManager->triggerListeners( ) ..\EventManager.php:207
11  1.2431  391096  call_user_func ( )  ..\EventManager.php:468
12  1.2431  391112  Zend\ModuleManager\Listener\ConfigListener->onLoadModule( ) ..\EventManager.php:468
13  1.2439  391464  Zend\ModuleManager\Listener\ConfigListener->addConfig( )    ..\ConfigListener.php:127

What is problem with it? I tried to debug it but I don't know what is wrong with my code, except that is int value even I return array in config/module.config.php.

Ps. Eariler, I didn't use Xdebug (+PHPStorm), and when eg I put breakpoint somewhere into config/module.config.php, it skips this breakpoint and go into (it don't even shows) and goes into ZF library files (where for example is another breakpoint). Is it normal or I'm doing sth wrong?


回答1:


Your module/Album/config/module.config.php file is empty, while it should return a config array (like in the example code you've posted).




回答2:


I had this same problem when I was about creating a new module after some time. I had other modules that were already working but this other one was giving the error you have now. In my search I realized that I wrote:

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

instead of:

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

in my Module.php file. After correcting it my app works great! Please look through your code carefully especially in the Module.php and module.config.php files for omissions etc. Good luck!



来源:https://stackoverflow.com/questions/16841797/zf-2-tutorial-application-config-being-merged-must-be-an-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!