2011-10-31 15 views
5

ターミナルでカスタムyiicコマンドを実行すると、以下のエラーが表示されます。カスタムコマンドを実行中にyiiエラーが発生しました

私はこのエラーの原因を追跡しているようには見えません。誰も正しい方向に向けることができます。私は、アプリケーションの他の部分が動作するようにDBが正常に動作していることを知っています。

<?php 

    class RbacCommand extends CConsoleCommand 
    { 
     private $_authManager; 

     public function getHelp() 
     { 
      return "<<<EOD 

      USAGE 
       rbac 

      DESCRIPTION 
       This command generates an initial RBAC authorization hierarchy. 

      EOD"; 
     } 

     public function run($args) 
     { 
      if(($this->_authManager=Yii::app()->authManager)===null) 
      { 
       echo "Error: an authorization manager, named 'authManager' must be configured to use this command.\n"; 
       echo "If you already added 'authManager' component in applicaton configuration,\n"; 
       echo "please quit and re-enter the yiic shell.\n"; 
       return; 
      } 

      echo "This command will create three roles: Owner, Member, and Reader and the following permissions:\n"; 
      echo "create, read, update and delete user\n"; 
      echo "create, read, update and delete project\n"; 
      echo "create, read, update and delete issue\n"; 
      echo "Would you like to continue? [Yes|No]"; 

      if(!strncasecmp(trim(fgets(STDIN)),'y',1)) 
      { 
       $this->_authManager->clearAll(); 

       $this->_authManager->createOperation("createUser","create a new user"); 
       $this->_authManager->createOperation("readUser","read user profile information"); 
       $this->_authManager->createOperation("updateUser","update a users information"); 
       $this->_authManager->createOperation("deleteUser","remove a user from a project"); 

       $this->_authManager->createOperation("createProject","create a new project"); 
       $this->_authManager->createOperation("readProject","read project information"); 
       $this->_authManager->createOperation("updateProject","update project information"); 
       $this->_authManager->createOperation("deleteProject","delete a project"); 

       $this->_authManager->createOperation("createIssue","create a new issue"); 
       $this->_authManager->createOperation("readIssue","read issue information"); 
       $this->_authManager->createOperation("updateIssue","update issue information"); 
       $this->_authManager->createOperation("deleteIssue","delete a issue"); 

       $role=$this->_authManager->createRole("member"); 
       $role->addChild("reader"); 
       $role->addChild("createIssue"); 
       $role->addChild("updateIssue"); 
       $role->addChild("deleteIssue"); 

       $role=$this->_authManager->createRole("owner"); 
       $role->addChild("reader"); 
       $role->addChild("member"); 
       $role->addChild("createUser"); 
       $role->addChild("updateUser"); 
       $role->addChild("deleteUser"); 
       $role->addChild("createProject"); 
       $role->addChild("updateProject"); 
       $role->addChild("deleteProject"); 
      } 
     } 
    } 

?> 



users-MacBook-Air:protected user$ ./yiic shell ../index.php 
Yii Interactive Tool v1.1 (based on Yii v1.1.2) 
Please type 'help' for help. Type 'exit' to quit. 
>> rbac 

Warning: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in /Users/user/Dropbox/localhost/yii/framework/db/CDbConnection.php on line 302 
exception 'CDbException' with message 'CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] No such file or directory' in /Users/user/Dropbox/localhost/yii/framework/db/CDbConnection.php:267 
Stack trace: 
#0 /Users/user/Dropbox/localhost/yii/framework/db/CDbConnection.php(242): CDbConnection->open() 
#1 /Users/user/Dropbox/localhost/yii/framework/db/CDbConnection.php(221): CDbConnection->setActive(true) 
#2 /Users/user/Dropbox/localhost/yii/framework/base/CModule.php(363): CDbConnection->init() 
#3 /Users/user/Dropbox/localhost/yii/framework/web/auth/CDbAuthManager.php(570): CModule->getComponent('db') 
#4 /Users/user/Dropbox/localhost/yii/framework/web/auth/CDbAuthManager.php(69): CDbAuthManager->getDbConnection() 
#5 /Users/user/Dropbox/localhost/yii/framework/base/CModule.php(363): CDbAuthManager->init() 
#6 /Users/user/Dropbox/localhost/yii/framework/base/CModule.php(86): CModule->getComponent('authManager') 
#7 /Users/user/Dropbox/localhost/trackstar/protected/commands/shell/RbacCommand.php(22): CModule->__get('authManager') 
#8 /Users/user/Dropbox/localhost/yii/framework/cli/commands/ShellCommand.php(144): RbacCommand->run(Array) 
#9 /Users/user/Dropbox/localhost/yii/framework/cli/commands/ShellCommand.php(99): ShellCommand->runShell() 
#10 /Users/user/Dropbox/localhost/yii/framework/console/CConsoleCommandRunner.php(62): ShellCommand->run(Array) 
#11 /Users/user/Dropbox/localhost/yii/framework/console/CConsoleApplication.php(88): CConsoleCommandRunner->run(Array) 
#12 /Users/user/Dropbox/localhost/yii/framework/base/CApplication.php(135): CConsoleApplication->processRequest() 
#13 /Users/user/Dropbox/localhost/yii/framework/yiic.php(33): CApplication->run() 
#14 /Users/user/Dropbox/localhost/trackstar/protected/yiic.php(7): require_once('/Users/user/Dro...') 
#15 /Users/user/Dropbox/localhost/trackstar/protected/yiic(4): require_once('/Users/user/Dro...') 
#16 {main} 
>> 

答えて

11

試してください:あなたの接続文字列で127.0.0.1

変更localhost

OR:

は、あなたの接続文字列にunix_socket=/path/to/socketを追加します。デフォルトでは

+1

は、魅力のように動作します –

+0

は最初のオプションを試してみました。それは動作します:) – fortm

+0

第2は私のためにそれを解決しました! – darkheir

0

、Yiiはprotected/config/に異なる設定ファイルを使用します(単位)テストのために、ウェブのための

  • main.phpをCLIため
  • console.php
  • test.php

DB接続をmain.phpに設定していますが、console.phpで忘れてしまった可能性があります。

関連する問題