Пример #1
0
 /**
  * @inheritdoc
  * @throws InvalidConfigException
  */
 public function init()
 {
     foreach (['form', 'model', 'fields'] as $attribute) {
         if ($this->{$attribute} === null) {
             throw new InvalidConfigException(self::className() . '::' . $attribute . ' should be set');
         }
     }
     if (!$this->form instanceof ActiveForm) {
         throw new InvalidConfigException(self::className() . '::form' . ' should be instance of ' . ActiveForm::className());
     }
     parent::init();
 }
Пример #2
0
 /**
  * @inheritdoc
  */
 public function run($id)
 {
     /* @var $model Model|ActiveRecordInterface|\yii2tech\ar\variation\VariationBehavior */
     $model = $this->findModel($id);
     $model->scenario = $this->scenario;
     $post = Yii::$app->request->post();
     if ($model->load($post) && Model::loadMultiple($model->getVariationModels(), $post)) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return call_user_func_array([ActiveForm::className(), 'validate'], array_merge([$model, $model->getVariationModels()]));
         }
         if ($model->save()) {
             $url = array_merge(['view'], Yii::$app->request->getQueryParams(), ['id' => implode(',', array_values($model->getPrimaryKey(true)))]);
             return $this->controller->redirect($url);
         }
     }
     return $this->controller->render($this->view, ['model' => $model]);
 }
Пример #3
0
 /**
  * Performs AJAX validation of the role models via [[ActiveForm::validate()]].
  * @param ActionEvent $event event instance.
  */
 public function afterAjaxValidate($event)
 {
     $model = $event->model;
     $roleModels = $this->getRoleModels($model);
     $event->result = array_merge($event->result, call_user_func_array([ActiveForm::className(), 'validate'], $roleModels));
 }