コード例 #1
0
ファイル: Form.php プロジェクト: tuyakhov/yii2-form-builder
 /**
  * @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
ファイル: VariationUpdate.php プロジェクト: vall12/admin
 /**
  * @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
ファイル: RoleBehavior.php プロジェクト: yii2tech/admin
 /**
  * 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));
 }