public function actionImport() { $Model = new DotaTeam(); $file = Yii::getAlias('@backend') . $Model->jsonFile; //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']['teams'])) { /* $inDb = []; $inDb1 = $Model->find()->all(); foreach($inDb1 as $i) { $inDb[$i->leagueid] = $i; } echo'<pre>';print_r($isDb1);echo'</pre>';die; */ foreach ($rows['result']['teams'] as $item) { $model = new DotaTeam(); $model->attributes = $item; $model->logo = (string) $model->logo; $model->logo_sponsor = (string) $model->logo_sponsor; $model->save(); //echo'<pre>';print_r($model->attributes);echo'</pre>';die; //echo'<pre>';print_r($model);echo'</pre>';die; } } return $this->redirect(['index']); }
public function upload() { if ($this->validate()) { $this->path = Yii::getAlias('@frontend') . '/web/' . Yii::$app->params['players-path']; foreach ($this->imageFiles as $file) { $this->filename = DFileHelper::getRandomFileName($this->path, $file->extension) . '.' . $file->extension; $file->saveAs($this->path . '/' . $this->filename); } return true; } else { return false; } }
public function actionDeleteFoto($id) { $model = $this->findModel($id); DFileHelper::deleteFile($model->foto, 'players'); $model->foto = ''; $model->save(false); return $this->redirect(['update', 'id' => $model->account_id]); }
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']); }