PHP Fatal Error 'yii \ base \ ErrorException' with message 'Class' app \ commands \ Yii 'not found'

in /home/c/co75701/yii2/public_html/commands/CountriesController.php:36

Stack trace:
0 [internal function]: yii \ base \ ErrorHandler-> handleFatalError () 1 {main}

Line 36 is the beginning of a 3-line query:

Yii::$app->db->createCommand()->batchInsert('countries', ['country'], $countries )->execute(); 

$countries - an ordinary array of countries.

  • do you have a line in the controller use app\commands\Yii ? - Bookin
  • one
    Add use yii; or a slash before calling \Yii:$app . PS Usually IDE (PhpStorm exactly) suggest the absence of a declaration. - Ninazu
  • use app \ commands \ Yii - spelled out, but if I put a slash in front of \ Yii: $ app, then the error is: with message 'Invalid argument for foreach () /yii2/db/QueryBuilder.php:214 - Timur Musharapov
  • What does "ordinary array of countries" mean? What exactly is in $countries ? Most likely the problem in this array is oakymax
  • replace use app\commands\Yii with use \Yii , if you don’t have of course the class that’s used here. If there is something or as you wrote above, or use alliances in use . The error Invalid argument supplied for foreach() does not apply to the question, but maybe just $countries empty, or else there is an error. - Bookin

0