public function actionIndex() { $lst = Lines::find()->where([RECORD_STATUS => STATUS_NORMAL])->orderBy(NAME)->all(); $lstStation = []; if (count($lst) > 0) { foreach ($lst as $item) { $stations = Stations::find()->where([LINE_ID => $item->id, RECORD_STATUS => STATUS_NORMAL])->all(); if (count($stations) > 0) { array_push($lstStation, ['line' => $item, 'stations' => $stations]); } } } return $this->render('index', ['listLine' => $lst, 'listStation' => $lstStation]); }
public function actionCreate($id = null) { $lstLine = Lines::find()->where([RECORD_STATUS => STATUS_NORMAL])->all(); $model = new Stations(); if ($model->load(Yii::$app->request->post())) { if ($model->validate()) { $model->save(); $id = $model->id; $model->file = UploadedFile::getInstance($model, 'file'); if ($model->file) { $id = $model->id; $imageName = "station_" . $id . '_' . getdate()[0]; $model->file->saveAs('uploads/' . $imageName . '.' . $model->file->extension); $station = Stations::findOne($id); $station->image = '@web/uploads/' . $imageName . '.' . $model->file->extension; $station->save(); } return $this->redirect(['station/index']); } } else { return $this->render('create', ['model' => $model, 'listLine' => $lstLine, 'currentLine' => $id]); } }