2017-03-16 2 views
1

Wenn ich die Befehlssteuerung über Klemme ausführen, die Yii::getAlias('@webroot') funktioniert nicht =/Yii2 - Kommando-Controller funktioniert nicht getalias Webroot

Befehl (QueuePushNotificationController.php):

<?php 
    namespace app\commands; 

    use Yii; 
    use yii\console\Controller; 

    class QueuePushNotificationController extends Controller 
    { 
     public function actionIndex() 
     { 
      echo Yii::getAlias('@webroot'); 
     } 
    } 

über das Terminal ausführen:

./yii queue-push-notification 

Rückkehr:

Exception 'yii\base\InvalidParamException' with message 'Invalid path alias: @webroot' 

Funktioniert die Anwendung nicht?

Vielen Dank!

Antwort

3

in yii2 Befehl undefind (Webroot oder Web) alias, Web index.php yii \ web \ application.php defind Methode

protected function bootstrap() 
{ 
     $request = $this->getRequest(); 
     Yii::setAlias('@webroot', dirname($request->getScriptFile())); 
     Yii::setAlias('@web', $request->getBaseUrl()); 

     parent::bootstrap(); 
} 

aber können Sie yii \ Konsole \ Application kein Bootstrap() -Methode sehen . Sie können dieses Problem gut lösen,

public function init() 
{ 
     Yii::setAlias('@webroot', Specific path); 
     Yii::setAlias('@web', Specific path); 
     parent::init(); // TODO: Change the autogenerated stub 
}