ZF2 Zend framework未为相册教程应用程序调用global.php

ZF2 Zend framework未为相册教程应用程序调用global.php,php,phpunit,zend-framework2,Php,Phpunit,Zend Framework2,我收到一个错误:Zend\ServiceManager\Exception\ServiceNotCreateException:在创建“Zend\Db\Adapter\Adapter”时引发了一个异常;没有返回任何实例 追根究底,我发现Zend\Db\Adapter\Adapter出现在global.php中。但是,global.php从未被调用,或者至少在module.php getserviceconfig()之前没有被调用过,在module.php getserviceconfig()之前

我收到一个错误:Zend\ServiceManager\Exception\ServiceNotCreateException:在创建“Zend\Db\Adapter\Adapter”时引发了一个异常;没有返回任何实例

追根究底,我发现Zend\Db\Adapter\Adapter出现在global.php中。但是,global.php从未被调用,或者至少在module.php getserviceconfig()之前没有被调用过,在module.php getserviceconfig()之前,错误会被触发。testconfig.php.dist和application.config.php都向侦听器定义提供global.php。但是,global.php从不执行

有人能告诉我为什么吗?定义如下

global.php

<?php
echo PHP_EOL . "Global.php executed." . PHP_EOL;
return array(
    'db' => array(
        'driver'         => 'Pdo',
        'dsn'            => 'mysql:dbname=zf2tutorial;host=album.techmate.com',
        'driver_options' => array(
            PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
        ),
    ),
    'service_manager' => array(
        'factories' => array(
            'Zend\Db\Adapter\Adapter'
                    => 'Zend\Db\Adapter\AdapterServiceFactory',
        ),
    ),
);
?>

我认为global.php没有自动加载,因为文件的命名不匹配:

'config/autoload/{,*.}{global,local}.php',

因此,如果您将文件命名为
myconfig.global.php
,则应将其拾取。

我认为global.php没有自动加载,因为文件的命名不匹配:

'config/autoload/{,*.}{global,local}.php',

因此,如果您将文件命名为
myconfig.global.php
,则应将其选中。

我找到了解决此问题的方法,但我对需要这样做感到非常失望。在阅读ZF2手册时,我发现一个注意事项,即ModuleManager应该将global.php和local.php与module.config.php合并。据我所见,这实际上应该发生在ModuleManager工厂中,但是

在任何情况下,我都会将global.php和local.php信息手动添加到module.config.php中。这是可行的,但也不必要

和往常一样,我很高兴收到比这个更好的答案

为了清楚起见,我将手册参考纳入其中。它来自700页。请注意,它还包含一个调用文件my.global.config.php和my.local.config.php的错误。我确实试过那些名字以防万一,但那不起作用

154.5 Default Configuration Options
The following options are available when using the default services configured by the ServiceManagerConfig
and ViewManager.
These configuration directives can go to the config/autoload/{,*.}{global,local}.php files, or in the
module/<module name>/config/module.config.php configuration files. The merging of these configuration
files is done by the ModuleManager. It first merges each module’s module.config.php file, and then
the files in config/autoload (first the *.global.php and then the *.local.php files). The order of the
merge is relevant so you can override a module’s configuration with your application configuration. If you have both
a config/autoload/my.global.config.php and config/autoload/my.local.config.php, the
local configuration file overrides the global configuration.
154.5默认配置选项
使用ServiceManagerConfig配置的默认服务时,以下选项可用
和视图管理器。
这些配置指令可以转到config/autoload/{、*.}{global、local}.php文件,或者在
module//config/module.config.php配置文件。这些配置的合并
文件由ModuleManager完成。它首先合并每个模块的module.config.php文件,然后
config/autoload中的文件(首先是*.global.php文件,然后是*.local.php文件)。秩序
合并是相关的,因此您可以用应用程序配置覆盖模块的配置。如果两者都有
config/autoload/my.global.config.php和config/autoload/my.local.config.php
本地配置文件覆盖全局配置。

我找到了解决此问题的方法,但我对需要这样做感到非常失望。在阅读ZF2手册时,我发现一个注意事项,即ModuleManager应该将global.php和local.php与module.config.php合并。据我所见,这实际上应该发生在ModuleManager工厂中,但是

在任何情况下,我都会将global.php和local.php信息手动添加到module.config.php中。这是可行的,但也不必要

和往常一样,我很高兴收到比这个更好的答案

为了清楚起见,我将手册参考纳入其中。它来自700页。请注意,它还包含一个调用文件my.global.config.php和my.local.config.php的错误。我确实试过那些名字以防万一,但那不起作用

154.5 Default Configuration Options
The following options are available when using the default services configured by the ServiceManagerConfig
and ViewManager.
These configuration directives can go to the config/autoload/{,*.}{global,local}.php files, or in the
module/<module name>/config/module.config.php configuration files. The merging of these configuration
files is done by the ModuleManager. It first merges each module’s module.config.php file, and then
the files in config/autoload (first the *.global.php and then the *.local.php files). The order of the
merge is relevant so you can override a module’s configuration with your application configuration. If you have both
a config/autoload/my.global.config.php and config/autoload/my.local.config.php, the
local configuration file overrides the global configuration.
154.5默认配置选项
使用ServiceManagerConfig配置的默认服务时,以下选项可用
和视图管理器。
这些配置指令可以转到config/autoload/{、*.}{global、local}.php文件,或者在
module//config/module.config.php配置文件。这些配置的合并
文件由ModuleManager完成。它首先合并每个模块的module.config.php文件,然后
config/autoload中的文件(首先是*.global.php文件,然后是*.local.php文件)。秩序
合并是相关的,因此您可以用应用程序配置覆盖模块的配置。如果两者都有
config/autoload/my.global.config.php和config/autoload/my.local.config.php
本地配置文件覆盖全局配置。
根据,在
TestConfig.php.dist
中,以下行可能是错误的:

'config/autoload/{,*.}{global,local}.php',
将行更改为:

'../../../config/autoload/{,*.}{global,local}.php',
如果您有一个
local.php
config文件,它也可能不会被加载

当然,如果目录结构是非标准的,则相应地更改该行,但您知道了。

根据,在
TestConfig.php.dist
中,以下行可能是错误的:

'config/autoload/{,*.}{global,local}.php',
将行更改为:

'../../../config/autoload/{,*.}{global,local}.php',
如果您有一个
local.php
config文件,它也可能不会被加载


当然,如果目录结构是非标准的,那么相应地更改行,但是您得到了这个想法。

好吧,这是一个公平的选择,但是,不,结果是一样的。我非常感谢您的回复…RGI发现这是整个解决方案的必要组成部分。谢谢。嗯,这是一个公平的机会,但是,不,结果是一样的。我非常感谢您的回复…RGI发现这是整个解决方案的必要组成部分。谢谢。这是绝对正确的。我刚刚在Zend论坛上发布了回复,正要在这里发布,这时我找到了你的答案。您的答案访问zf2 tutorial/config/autoload,这可能是最好的情况。但是,本教程将其放在Album/config/autoload中。在这种情况下,该行应读为../config/autoload/{,*.}{global,local}.php,只要您了解结构并访问存储它们的文件,这两种方法都可以。另一个注意事项是,我必须在global.php和local.php上放置一个更高级别的节点来匹配它,即myconfig.global.php。我必须执行:/config/autoload/{,*.}{global,local}。php@DominicWatson; 请注意,该文件