I am creating a console application where I would like to fetch data from another url whenever the command is run
This is how I have implemented the console controller
<?php
namespace console\controllers;
use yii\helpers\Console;
use yii\console\Controller;
... other use imports
use Yii;
class UserController extends Controller
{
public function actionInit()
{
$urltofetchdata = "https://urltofetchjsondata"; //i expect to return json
$datas= //how do i get the data here so that i can proceedby
foreach($datas as $data){
$user = new User();
$user->name = $data->name;
$user->email = $data->email;
$user->save();
}
}
}
so that when a user types:
./yii user/init
the data can be retrieved.