/** * @param array $params * @throws \yii\base\InvalidParamException */ public function __construct($params) { $this->scenario = 'search'; parent::__construct($params); if ($this->model === null) { throw new InvalidParamException('Param "model" cannot be empty'); } $this->rules = $this->model->rules(); $this->scenarios = $this->model->scenarios(); foreach ($this->safeAttributes() as $attribute) { $this->attributes[$attribute] = ''; } }
/** * @return array Validation rules */ public function rules() { $items = parent::rules(); if ($this->hasAttribute('created_at')) { $items[] = ['created_at', 'safe']; } if ($this->hasAttribute('updated_at')) { $items[] = ['updated_at', 'safe']; } return $items; }
/** * Make safe validation rules for behavior relations * @return array */ public function rules() { $fields = []; foreach ($this->behaviors as $behavior) { if ($behavior instanceof HasRelation) { $fields[] = $behavior->getAttributeName(); if ($behavior instanceof HasOneRelation) { $fields[] = $behavior->selfField; } } } return array_merge(parent::rules(), [[$fields, 'safe']]); }
/** * @inheritdoc */ public function rules() { $rules = parent::rules(); $options = []; for ($i = 1; $i <= Message::OPTIONS_COUNT; $i++) { $options[] = 'option_' . $i; } $rules[] = [['created_user_id', 'created_user_name', 'created_ip'], 'required']; $rules[] = [array_merge(['content'], $options), 'string']; $rules[] = [['status', 'created_user_id', 'updated_user_id', 'for_document_id', 'for_user_id', 'parent_message_id'], 'integer']; $rules[] = [['title', 'attachment', 'created_user_name', 'updated_user_name'], 'string', 'max' => 255]; $rules[] = [['created_ip'], 'string', 'max' => 19]; $rules[] = [['content', 'title'], 'filter', 'filter' => 'trim']; $rules[] = [['status'], 'default', 'value' => self::STATUS_ACTIVE]; $rules[] = [array_merge(['title', 'content', 'attachment', 'updated_at', 'updated_user_id', 'updated_user_name', 'for_document_id', 'for_user_id', 'parent_message_id'], $options), 'default', 'value' => null]; $rules[] = [['created_at', 'updated_at'], 'safe']; return $rules; }
/** * @inheritdoc */ public function rules() { $rules = parent::rules(); $rules[] = [['name'], 'required']; $rules[] = [['name'], 'unique']; $options_name = []; $options_type = []; $options_param = []; $options_require = []; for ($i = 1; $i <= self::OPTIONS_COUNT; $i++) { $options_name[] = 'option_' . $i . '_name'; $options_type[] = 'option_' . $i . '_type'; $options_param[] = 'option_' . $i . '_param'; $options_require[] = 'option_' . $i . '_require'; } $rules[] = [array_merge(['name', 'path'], $options_name, $options_param), 'string', 'max' => 255]; $rules[] = [array_merge($options_type, $options_require), 'integer']; $rules[] = [array_merge($options_name, ['name']), 'filter', 'filter' => 'trim']; $rules[] = [$options_require, 'default', 'value' => 0]; $rules[] = [array_merge($options_type, $options_name, $options_param), 'default', 'value' => null]; return $rules; }
public function rules() { $rules = parent::rules(); $rules[] = [['changeTenant'], 'safe']; return $rules; }
/** * @inheritdoc */ public function rules() { return array_merge(parent::rules(), [['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]], ['status', 'default', 'value' => self::STATUS_ACTIVE]]); }
/** * @inheritdoc */ public function rules() { $rules = parent::rules(); $options = []; for ($i = 1; $i <= Template::OPTIONS_COUNT; $i++) { $options[] = 'option_' . $i; } $rules[] = [['created_at', 'created_user_id', 'created_user_name', 'alias', 'name', 'parent_id', 'root_id', 'template_id', 'status'], 'required']; $rules[] = [['created_user_id', 'updated_user_id', 'template_id', 'parent_id', 'root_id', 'is_folder', 'status', 'last_parent_id', 'last_template_id'], 'integer']; $rules[] = ['alias', 'unique']; $rules[] = [array_merge(['annotation', 'content', 'meta_description', 'meta_keywords'], $options), 'string']; $rules[] = [['name', 'title', 'alias', 'img', 'created_user_name', 'updated_user_name', 'root_name', 'parent_name'], 'string', 'max' => 255]; $rules[] = ['status', 'in', 'range' => array_keys(self::getStatuses())]; $rules[] = [['name', 'title', 'alias'], 'filter', 'filter' => 'trim']; $rules[] = [array_merge(['title', 'annotation', 'meta_description', 'meta_keywords', 'content', 'img', 'updated_at', 'updated_user_id', 'updated_user_name', 'parent_name', 'root_name'], $options), 'default', 'value' => null]; $rules[] = [['status'], 'default', 'value' => self::STATUS_ACTIVE]; $rules[] = [['parent_id'], 'default', 'value' => 1]; $rules[] = [['is_folder'], 'default', 'value' => 0]; $rules[] = [['created_at', 'updated_at', 'fields'], 'safe']; return $rules; }
/** * @inheritDoc */ public function rules() { return ArrayHelper::merge(parent::rules(), [[['title'], RequiredValidator::class]]); }
public function getRules() { return $this->activeRecord->rules(); }
/** * @inheritdoc */ public function rules() { return array_merge(parent::rules(), [[['code'], 'required'], [['code'], 'unique'], [['code'], 'validateCode'], [['priority'], 'integer'], [['active'], 'string'], [['course'], 'number'], [['name', 'name_full'], 'safe']]); }