Esempio n. 1
0
 public function actionImport()
 {
     $heroModel = new DotaHero();
     $file = Yii::getAlias('@backend') . $heroModel->jsonHeroesFile;
     //echo'<pre>';print_r($heroModel->jsonHeroesFile);echo'</pre>';die;
     $rows = DFileHelper::readFromJsonFile($file);
     //echo'<pre>';print_r($rows);echo'</pre>';die;
     if (count($rows) && isset($rows['result']['heroes'])) {
         $heroesArr = $rows['result']['heroes'];
         foreach ($heroesArr as $heroItem) {
             $model = new DotaHero();
             $model->attributes = $heroItem;
             $model->save();
         }
     }
     return $this->redirect(['index']);
 }