本文整理汇总了PHP中yii\base\Model::rules方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::rules方法的具体用法?PHP Model::rules怎么用?PHP Model::rules使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\base\Model
的用法示例。
在下文中一共展示了Model::rules方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rules
public function rules()
{
$result = parent::rules();
foreach ($this->relatedElementModel->relatedProperties as $proeperty) {
$result = ArrayHelper::merge($result, $proeperty->rulesForActiveForm());
}
return $result;
}
示例2: testDefaults
public function testDefaults()
{
$singer = new Model();
$this->assertEquals([], $singer->rules());
$this->assertEquals([], $singer->attributeLabels());
}
示例3: buildParameters
public function buildParameters()
{
$rules = $this->originalModel->rules();
foreach ($rules as $rule) {
if (isset($rule['on']) && $rule['on'] !== $this->scenario) {
continue;
}
if (is_array($rule[0])) {
foreach ($rule[0] as $name) {
if (!isset($this->parameters[$name])) {
$this->parameters[$name] = [];
}
if ($rule[1] === 'required') {
$this->parameters[$name]['required'] = true;
}
if (in_array($rule[1], ['string', 'number', 'integer', 'boolean'])) {
$this->parameters[$name]['type'] = $rule[1];
}
if ($rule[1] === 'each') {
$this->parameters[$name]['type'] = Swagger::DATA_TYPE_ARRAY;
$this->parameters[$name]['items']['type'] = Swagger::DATA_TYPE_STRING;
}
}
} elseif (is_string($rule[0])) {
$name = $rule[0];
if (!isset($this->parameters[$name])) {
$this->parameters[$name] = [];
}
if ($rule[1] === 'required') {
$this->parameters[$name]['required'] = true;
}
if (in_array($rule[1], ['string', 'number', 'integer', 'boolean'])) {
$this->parameters[$name]['type'] = $rule[1];
}
if ($rule[1] === 'each') {
$this->parameters[$name]['type'] = Swagger::DATA_TYPE_ARRAY;
$this->parameters[$name]['items']['type'] = Swagger::DATA_TYPE_STRING;
}
}
}
foreach ($this->parameters as $name => $items) {
$this->parameters[$name]['description'] = $this->modelAnnotationParser->getPropertyDesc($name) ?: var2HumanReadable($name);
$this->parameters[$name]['required'] = isset($this->parameters[$name]['required']) ? $this->parameters[$name]['required'] : false;
if (!isset($this->parameters[$name]['type'])) {
if ($this->annotationParser->getPropertyType($name) === Swagger::DATA_TYPE_OBJECT) {
if (!is_null($objectClass = $this->annotationParser->getPropertyObjectClass($name))) {
$subFormModel = new FormModel(new $objectClass(), REST::SCENARIO_DEFAULT);
$this->subFormModels[] = $subFormModel;
$this->parameters[$name]['$ref'] = "#/definitions/{$subFormModel->name}";
} else {
$this->parameters[$name]['type'] = Swagger::DATA_TYPE_OBJECT;
}
} elseif ($this->annotationParser->getPropertyType($name) === Swagger::DATA_TYPE_OBJECT_ARRAY) {
$this->parameters[$name]['type'] = Swagger::DATA_TYPE_ARRAY;
if (!is_null($objectClass = $this->annotationParser->getPropertyObjectClass($name))) {
$subFormModel = new FormModel(new $objectClass(), REST::SCENARIO_DEFAULT);
$this->subFormModels[] = $subFormModel;
$this->parameters[$name]['items']['$ref'] = "#/definitions/{$subFormModel->name}";
} else {
$this->parameters[$name]['items']['type'] = Swagger::DATA_TYPE_STRING;
}
} else {
$this->parameters[$name]['type'] = Swagger::DATA_TYPE_STRING;
}
}
}
}
示例4: rules
public function rules()
{
return array_merge(parent::rules(), [[['oldpassword', 'newpassword'], 'required'], ['newpassword', 'string', 'min' => 6, 'max' => 16], ['oldpassword', 'checkPassword']]);
}