Example #1
0
 public function actionEdit($id)
 {
     $model = Menus::findOne($id);
     if ($model === null) {
         $this->flash('error', Yii::t('easyii', 'Not found'));
         return $this->redirect(['/admin/' . $this->module->id]);
     }
     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 {
             if (isset($_FILES) && $this->module->settings['enableThumb']) {
                 $model->image = UploadedFile::getInstance($model, 'image');
                 if ($model->image && $model->validate(['image'])) {
                     $model->image = Image::upload($model->image, 'news');
                 } else {
                     $model->image = $model->oldAttributes['image'];
                 }
             }
             if ($model->save()) {
                 $this->flash('success', Yii::t('easyii/menu', 'News updated'));
             } else {
                 $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors()));
             }
             return $this->refresh();
         }
     } else {
         return $this->render('edit', ['model' => $model]);
     }
 }
Example #2
0
 public function dbInstall()
 {
     $db = Yii::$app->db;
     $tableOptions = null;
     if ($db->driverName === 'mysql') {
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=MyISAM';
     }
     $db->createCommand()->createTable(Menus::tableName(), ['menu_id' => 'pk', 'parent_id' => Schema::TYPE_INTEGER . ' NOT NULL DEFAULT 0', 'label' => Schema::TYPE_STRING . '(120) NOT NULL', 'url' => Schema::TYPE_STRING . '(255) DEFAULT NULL', 'type' => Schema::TYPE_STRING . '(15) NOT NULL', 'is_mobile' => 'tinyint(1) NOT NULL DEFAULT 1', 'order_num' => Schema::TYPE_INTEGER . ' DEFAULT NULL', 'status' => 'tinyint(1) NOT NULL DEFAULT 1', 'created_at' => Schema::TYPE_INTEGER . ' unsigned NOT NULL', 'updated_at' => Schema::TYPE_INTEGER . ' unsigned NOT NULL'], $tableOptions)->execute();
 }
Example #3
0
 public function actionDelete($id)
 {
     if ($model = Menus::findOne($id)) {
         $model->delete();
     } else {
         $this->error = Yii::t('easyii', 'Not found');
     }
     return $this->formatResponse(Yii::t('easyii/menu', 'News deleted'));
 }