Пример #1
0
 protected function findModel($id)
 {
     if (($model = Category::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #2
0
 public function getArrayCategory()
 {
     return ArrayHelper::map(Category::find()->all(), 'id', 'title');
 }
Пример #3
0
 /**
  * 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 {
     
             }
     */
 }