3

我的环境(Zend 服务器):

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

所以我尝试用 ZF2 形式的官方教程编写我的第一个应用程序。

骨架应用中的 ZF 版本:2.2

这是我的项目的链接,如果有人想仔细看看的话。

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';
    }
}

这是我的错误:

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?我试图调试它,但我不知道我的代码有什么问题,除了它是 int 值,即使我在config/module.config.php.

附言。早些时候,我没有使用 Xdebug (+PHPStorm),例如,当我将断点放入 config/module.config.php. )。这是正常的还是我做错了什么?

4

2 回答 2

1

您的module/Album/config/module.config.php文件是空的,而它应该返回一个配置数组(就像您发布的示例代码一样)。

于 2013-05-30T17:10:35.097 回答
1

一段时间后,当我要创建一个新模块时,我遇到了同样的问题。我有其他模块已经在工作,但是另一个模块给出了你现在遇到的错误。在我的搜索中,我意识到我写道:

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

代替:

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

在我的 Module.php 文件中。更正后,我的应用程序运行良好!请仔细查看您的代码,尤其是在 Module.php 和 module.config.php 文件中是否有遗漏等。祝您好运!

于 2014-04-14T08:52:45.900 回答