Inserting records into a database in Yii2

Ok, Im trying to insert some records in the database by creating a command and then using insert like in the documentation I found, but I get error "class app\commands Yii" not found. Now I have this at the top of my controller

namespace app\commands;

use yii\console\Controller;

And this is the command i built




//added game to database

        foreach ($games as $g) 

        {

            //echo $g[0].'<br>'.$g[1].'<br>'.$g[2].'<br>'.$g[3].'<br>'.$g[4].'<br>'.$g[5].'<br><br>';

            //take the upper and put into database

            $command = Yii::app()->db->createCommand();


            $command->insert('nfl_lines',array('away'=>$g[0],'home'=>$g[1]));

            

        }



Would you:

  1. check once more from what class you are extending your class. Must be like:

namespace app\commands;


use Yii;

use yii\console\Controller;


class YourController extends Controller

{

...

}

  1. try to perform a command below:

$connection->createCommand()->insert('nfl_lines', [

    'away' => $g[0],

    'home' => $g[1],

])->execute();

Add


use Yii;