本文整理汇总了PHP中yii\db\ActiveRecord::rules方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::rules方法的具体用法?PHP ActiveRecord::rules怎么用?PHP ActiveRecord::rules使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::rules方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @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] = '';
}
}
示例2: rules
/**
* @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;
}
示例3: rules
/**
* 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']]);
}
示例4: rules
/**
* @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;
}
示例5: 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;
}
示例6: rules
public function rules()
{
$rules = parent::rules();
$rules[] = [['changeTenant'], 'safe'];
return $rules;
}
示例7: 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]]);
}
示例8: rules
/**
* @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;
}
示例9: rules
/**
* @inheritDoc
*/
public function rules()
{
return ArrayHelper::merge(parent::rules(), [[['title'], RequiredValidator::class]]);
}
示例10: getRules
public function getRules()
{
return $this->activeRecord->rules();
}
示例11: 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']]);
}