Doctrine orm ZF2和x2B;原则2:Cli工具的访问被拒绝

Doctrine orm ZF2和x2B;原则2:Cli工具的访问被拒绝,doctrine-orm,zend-framework2,Doctrine Orm,Zend Framework2,我有一个ZF2 2.1.3应用程序,里面有条令2 我使用composer安装了: "zendframework/zendframework": "2.*" ,"doctrine/doctrine-orm-module": "dev-master" A使用以下内容创建文件config/autoload/database.local.php: return array( 'doctrine' => array( 'connection' =

我有一个ZF2 2.1.3应用程序,里面有条令2

我使用composer安装了:

    "zendframework/zendframework": "2.*"
    ,"doctrine/doctrine-orm-module":       "dev-master"
A使用以下内容创建文件
config/autoload/database.local.php

return array(
    'doctrine' => array(
        'connection' => array(
            // Default connection name
            'orm_default' => array(
            'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
                'params' => array(
                    'host'     => 'localhost',
                    'port'     => '3306',
                    'dbname'   => 'zf2-experimental',
                    'user'     => 'root',
                    'password' => '',
                ),
            ),
        ),
    ),
);
我在
Foo
模块(
src/Business/entity/Bar.php
)下创建实体
Bar
,并在
module.config.php
上进行如下配置:

'doctrine' => array(
    'driver' => array(
        __NAMESPACE__ . '_driver' => array(
            'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
            'cache' => 'array',
            'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Business/Entity'),
        ),
        'orm_default' => array(
            'drivers' => array(
                __NAMESPACE__ . '\Business\Entity' => __NAMESPACE__ . '_driver',
            ),
        ),
    ),
),
好的!正好在

然后我创建一个简单的
Foo
实体并运行doctrine cli工具:

c:\wamp\www\zf2-Experimental>.\vendor\bin\doctrine-module.bat orm:validate-schema
    [Mapping]  OK - The mapping files are correct.

      [PDOException]
      SQLSTATE[28000] [1045] Access denied for user 'username'@'localhost' (using password: YES)

    orm:validate-schema
c:\wamp\www\zf2-Experimental>
看起来cli工具可以在my
config/autoload/database.local.php
中获取我的连接参数

在应用程序索引上,我测试了配置:

$config = $this->getServiceLocator()->get('config');
\Zend\Debug\Debug::dump($config['doctrine']['connection']['orm_default']);
结果是:

array (size=4)
  'configuration' => string 'orm_default' (length=11)
  'eventmanager' => string 'orm_default' (length=11)
  'params' => 
    array (size=5)
      'host' => string 'localhost' (length=9)
      'port' => string '3306' (length=4)
      'user' => string 'root' (length=4)
      'password' => string '' (length=0)
      'dbname' => string 'zf2-experimental' (length=16)
  'driverClass' => string 'Doctrine\DBAL\Driver\PDOMySql\Driver' (length=36)
有人能帮我吗?!:)
谢谢大家

嗯,我花了很多时间试图解决这个问题,最后终于解决了

我忘了提到我使用ZF1环境特定配置风格! 你可以看到

我用以下结构创建了数据库配置文件(我之前没有提到这一点,因为我认为它不会干扰这个问题):

因此,我的数据库配置实际上位于
config/autoload/app_env/development/database.local.php

复制时,将文件粘贴到
config/autoload/database.local.php
我的CLI工具可以工作

但是为什么呢?为什么Cli工具无法在另一个目录中查找配置文件? 有一种处理子文件夹的方法吗


谢谢你的帮助

由于映射文件已验证,因此错误肯定在连接参数内。您是否绝对确定您的
root
没有密码并且
dbname
正确SHey@Sam!我找到了答案!你能给我读一下并解释一下为什么会发生这种情况吗?非常感谢。我不知道它的内部结构,我建议你在关于webchat.freenode.net的条令中ping@Ocramius或其他任何人。他们的知识比我多。据我所知,应加载
自动加载下的所有配置。也许不是递归的,只是顶级的。老实说,没有线索
'module_listener_options' => array(
    'config_glob_paths'    => array(
        'config/autoload/{,*.}{global,local}.php',
        // Here! My config path is config/autoload/app_env/development/
        'config/autoload/app_env/' . (getenv('APPLICATION_ENV') ?: 'production') . '{,*.}.local.php',
    ),