コード例 #1
0
ファイル: ItemsController.php プロジェクト: kuzmiand/easyii
 public function actionCreate($id)
 {
     if (!($category = Carousel::findOne($id))) {
         return $this->redirect(['/admin/' . $this->module->id]);
     }
     $model = new ItemCarousel();
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         } else {
             $model->carousel_id = $category->primaryKey;
             if ($fileInstanse = UploadedFile::getInstance($model, 'image')) {
                 $model->image = $fileInstanse;
                 if ($model->validate(['image'])) {
                     $model->image = Image::upload($model->image, 'carousel');
                     $model->status = Carousel::STATUS_ON;
                     if ($model->save()) {
                         $this->flash('success', Yii::t('easyii/carousel', 'Carousel created'));
                         return $this->redirect(['/admin/' . $this->module->id]);
                     } else {
                         $this->flash('error', Yii::t('easyii', 'Create error. {0}', $model->formatErrors()));
                     }
                 } else {
                     $this->flash('error', Yii::t('easyii', 'Create error. {0}', $model->formatErrors()));
                 }
             } else {
                 $this->flash('error', Yii::t('yii', '{attribute} cannot be blank.', ['attribute' => $model->getAttributeLabel('image')]));
             }
             return $this->refresh();
         }
     } else {
         return $this->render('create', ['model' => $model, 'category' => $category]);
     }
 }
コード例 #2
0
ファイル: AController.php プロジェクト: kuzmiand/easyii
 public function actionDelete($id)
 {
     if ($model = Carousel::findOne($id)) {
         $model->delete();
     } else {
         $this->error = Yii::t('easyii', 'Not found');
     }
     return $this->formatResponse(Yii::t('easyii/carousel', 'Carousel item deleted'));
 }
コード例 #3
0
ファイル: Carousel.php プロジェクト: kuzmiand/easyii
 public function api_carousel_items($slug_carousel)
 {
     $carousel = CarouselsModel::find()->where(['slug' => $slug_carousel])->one();
     if ($carousel) {
         if (!$this->_carousel_items) {
             $this->_carousel_items = [];
             foreach (ItemCarousel::find()->status(ItemCarousel::STATUS_ON)->where(['carousel_id' => $carousel->carousel_id])->orderBy(['order_num' => SORT_DESC])->all() as $item) {
                 $this->_carousel_items[] = $item;
             }
         }
         return $this->_carousel_items;
     }
 }
コード例 #4
0
 public function down()
 {
     $this->dropTable(Carousels::tableName());
     $this->dropTable(ItemCarousel::tableName());
 }