public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Category::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }
public function getArrayCategory() { return ArrayHelper::map(Category::find()->all(), 'id', 'title'); }
/** * Updates an existing Article model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $category = Category::find()->all(); $oldAnonsImg = $model->anons_img; if ($model->load(Yii::$app->request->post())) { $model->anons_img = UploadedFile::getInstance($model, 'anons_img'); if ($model->validate()) { if ($model->anons_img) { $anonsImgName = $this->module->articleAnonsImgForbes . date('Ymdhis') . rand(1000, 9999) . '.' . $model->anons_img->extension; $model->anons_img->saveAs(Yii::getAlias('@app/web') . $anonsImgName); $model->anons_img = $anonsImgName; } else { $model->anons_img = $oldAnonsImg; } $model->author_id = Yii::$app->user->identity->getId(); $model->save(); Yii::$app->session->setFlash('success', Module::t('app', 'ARTICLE_FLASH_UPDATE_TRUE')); return $this->redirect(['view', 'id' => $model->id]); } else { Yii::$app->session->setFlash('error', Module::t('app', 'ARTICLE_FLASH_UPDATE_FALSE')); return $this->render('update', ['model' => $model, 'category' => $category]); } } else { return $this->render('update', ['model' => $model, 'category' => $category]); } /* * if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { } */ }