2013-03-05 23 views
2

我有一個原則2. ZF2 2.1.3應用ZF2 + 2原則:CLI工具具有拒絕訪問

我安裝使用作曲家:

"zendframework/zendframework": "2.*" 
    ,"doctrine/doctrine-orm-module":  "dev-master" 

一個創建一個文件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)創建我的實體Barmodule.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', 
      ), 
     ), 
    ), 
), 

好的!正是在Sam says here

然後,我創建一個簡單的Foo實體和運行學說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工具可以得到我的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) 

有人可以請幫我嗎? :) 謝謝大家!

+0

由於映射文件經過驗證,錯誤肯定在連接參數內。你確定你的'root'沒有密碼,'dbname'是正確的嗎? :S – Sam 2013-03-05 07:04:53

+0

嗨@Sam!我找到了答案!您能否請讀一讀並向我解釋爲什麼會發生這種情況?謝謝! – vinigarcia87 2013-03-05 16:22:49

回答

0

那麼,我浪費了很多時間來解決這個問題,最後呢。

我忘了提及我使用ZF1環境特定的配置風格! 你可以看到here

創建下面的結構我的數據庫配置文件(之前我沒有提到這一點,因爲我認爲這不會對這個問題干擾):

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

所以,我的數據庫CONFIGS實際上是在config/autoload/app_env/development/database.local.php

當我將文件複製粘貼到config/autoload/database.local.php時,我的CLI工具正常工作!

但爲什麼?爲什麼Cli工具不能在另一個目錄中查找配置文件? 有一種方法來處理子文件夾?

感謝您的幫助!

+0

我不知道內部,我會建議你在#doctrine中關於這個webchat.freenode.net或任何其他人在@Ocramius中執行ping操作。他們比我有更多的知識。據我的理解,應該加載'autoload'下的所有配置。也許不是遞歸的,只有頂層。沒有線索,說實話 – Sam 2013-03-05 16:54:28