Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if I am in 'console' mode

Tags:

yii2

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 variables that are set in the GUI.

Is it possible to tell which mode I am in? Is there some environment variable automatically set, or should I just set some session variable in the console app to indicate the state?

like image 728
Martin Avatar asked Jun 03 '15 23:06

Martin


1 Answers

You can use

if (Yii::$app instanceof \yii\console\Application)

for console, and

if (Yii::$app instanceof \yii\web\Application)

for web.

like image 80
Maddelynne P Avatar answered Oct 08 '22 09:10

Maddelynne P