Ejemplo n.º 1
0
 /**
  * Create form
  *
  * @param null $parent
  * @return array|string|\yii\web\Response
  * @throws \yii\web\HttpException
  */
 public function actionCreate($parent = null)
 {
     $class = $this->categoryClass;
     $model = new $class();
     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['categoryThumb']) {
                 $model->image = UploadedFile::getInstance($model, 'image');
                 if ($model->image && $model->validate(['image'])) {
                     $model->image = Image::upload($model->image, $this->moduleName);
                 } else {
                     $model->image = '';
                 }
             }
             $model->status = $class::STATUS_ON;
             $parent = (int) Yii::$app->request->post('parent', null);
             if ($parent > 0 && ($parentCategory = $class::findOne($parent))) {
                 $model->order_num = $parentCategory->order_num;
                 $model->appendTo($parentCategory);
             } else {
                 $model->attachBehavior('sortable', SortableModel::className());
                 $model->makeRoot();
             }
             if (!$model->hasErrors()) {
                 $this->flash('success', Yii::t('easyii', 'Category created'));
                 return $this->redirect(['/populac/' . $this->moduleName, 'id' => $model->primaryKey]);
             } else {
                 $this->flash('error', Yii::t('easyii', 'Create error. {0}', $model->formatErrors()));
                 return $this->refresh();
             }
         }
     } else {
         return $this->render('@common/populac/views/category/create', ['model' => $model, 'parent' => $parent]);
     }
 }
Ejemplo n.º 2
0
 public function behaviors()
 {
     return [SortableModel::className()];
 }
Ejemplo n.º 3
0
 public function behaviors()
 {
     return [CacheFlush::className(), SortableModel::className()];
 }
Ejemplo n.º 4
0
 /**
  * @inheritDoc
  */
 public function behaviors()
 {
     return ArrayHelper::merge(parent::behaviors(), ['timestamp' => ['class' => TimestampBehavior::className()], 'blame' => ['class' => BlameableBehavior::className()], 'ARLog' => ['class' => ARLogBehavior::className()], 'sortable' => ['class' => SortableModel::className()]]);
 }
Ejemplo n.º 5
0
 public function behaviors()
 {
     return ['taggabble' => Taggable::className(), 'sluggable' => ['class' => SluggableBehavior::className(), 'attribute' => 'title', 'ensureUnique' => true], 'timestamp' => ['class' => TimestampBehavior::className()], 'blame' => ['class' => BlameableBehavior::className()], 'sortable' => ['class' => SortableModel::className()], 'audit' => ['class' => ARLogBehavior::className()]];
 }
Ejemplo n.º 6
0
 /**
  * @inheritDoc
  */
 public function behaviors()
 {
     return ArrayHelper::merge(parent::behaviors(), [TimestampBehavior::className(), BlameableBehavior::className(), ARLogBehavior::className(), SortableModel::className()]);
 }