How to detect if I am in 'console' mode

后端 未结 7 3258
死守一世寂寞
死守一世寂寞 2021-02-20 18:45

I am writing an app that runs from the browser. However, some model functions are also called from the Yii2 console. Therefore, I am getting errors when trying to access variabl

7条回答
  •  Happy的楠姐
    2021-02-20 19:06

    By default for console:

    Yii::$app->id == 'basic-console'
    

    And for web application:

    Yii::$app->id == 'basic'
    

    Yii::$app->id stores the id of the loaded configuration params. By default for console application it is 'basic-console' and for web application it is 'basic' (defined in configuration file)

提交回复
热议问题