메소드 | 설명 | |
---|---|---|
activeAttributes ( ) : string[] | Returns the attribute names that are subject to validation in the current scenario. | |
addError ( string $attribute, string $error = '' ) | Adds a new error to the specified attribute. | |
addErrors ( array $items ) | Adds a list of errors. | |
afterValidate ( ) | This method is invoked after validation ends. | |
attributeHints ( ) : array | Returns the attribute hints. | |
attributeLabels ( ) : array | Returns the attribute labels. | |
attributes ( ) : array | Returns the list of attribute names. | |
beforeValidate ( ) : boolean | This method is invoked before validation starts. | |
clearErrors ( string $attribute = null ) | Removes errors for all attributes or a single attribute. | |
createValidators ( ) : ArrayObject | Creates validator objects based on the validation rules specified in Model::rules. | |
fields ( ) : array | Returns the list of fields that should be returned by default by [[toArray()]] when no specific fields are specified. | |
formName ( ) : string | Returns the form name that this model class should use. | |
generateAttributeLabel ( string $name ) : string | Generates a user friendly attribute label based on the give attribute name. | |
getActiveValidators ( string $attribute = null ) : |
Returns the validators applicable to the current [[scenario]]. | |
getAttributeHint ( string $attribute ) : string | Returns the text hint for the specified attribute. | |
getAttributeLabel ( string $attribute ) : string | Returns the text label for the specified attribute. | |
getAttributes ( array $names = null, array $except = [] ) : array | Returns attribute values. | |
getErrors ( string $attribute = null ) : array | Returns the errors for all attributes or a single attribute. | |
getFirstError ( string $attribute ) : string | Returns the first error of the specified attribute. | |
getFirstErrors ( ) : array | Returns the first error of every attribute in the model. | |
getIterator ( ) : ArrayIterator | Returns an iterator for traversing the attributes in the model. | |
getScenario ( ) : string | Returns the scenario that this model is used in. | |
getValidators ( ) : ArrayObjec\ArrayObject | |
Returns all the validators declared in Model::rules. | |
hasErrors ( string | null $attribute = null ) : boolean | Returns a value indicating whether there is any validation error. | |
isAttributeActive ( string $attribute ) : boolean | Returns a value indicating whether the attribute is active in the current scenario. | |
isAttributeRequired ( string $attribute ) : boolean | Returns a value indicating whether the attribute is required. | |
isAttributeSafe ( string $attribute ) : boolean | Returns a value indicating whether the attribute is safe for massive assignments. | |
load ( array $data, string $formName = null ) : boolean | Populates the model with input data. | |
loadMultiple ( array $models, array $data, string $formName = null ) : boolean | Populates a set of models with the data from end user. | |
offsetExists ( mixed $offset ) : boolean | Returns whether there is an element at the specified offset. | |
offsetGet ( mixed $offset ) : mixed | Returns the element at the specified offset. | |
offsetSet ( integer $offset, mixed $item ) | Sets the element at the specified offset. | |
offsetUnset ( mixed $offset ) | Sets the element value at the specified offset to null. | |
onUnsafeAttribute ( string $name, mixed $value ) | This method is invoked when an unsafe attribute is being massively assigned. | |
rules ( ) : array | Returns the validation rules for attributes. | |
safeAttributes ( ) : string[] | Returns the attribute names that are safe to be massively assigned in the current scenario. | |
scenarios ( ) : array | Returns a list of scenarios and the corresponding active attributes. | |
setAttributes ( array $values, boolean $safeOnly = true ) | Sets the attribute values in a massive way. | |
setScenario ( string $value ) | Sets the scenario for the model. | |
validate ( array $attributeNames = null, boolean $clearErrors = true ) : boolean | Performs the data validation. | |
validateMultiple ( array $models, array $attributeNames = null ) : boolean | Validates multiple models. |
public activeAttributes ( ) : string[] | ||
리턴 | string[] | safe attribute names |
public addErrors ( array $items ) | ||
$items | array | a list of errors. The array keys must be attribute names. The array values should be error messages. If an attribute has multiple errors, these errors must be given in terms of an array. You may use the result of [[getErrors()]] as the value for this parameter. |
public afterValidate ( ) |
public attributeHints ( ) : array | ||
리턴 | array | attribute hints (name => hint) |
public attributeLabels ( ) : array | ||
리턴 | array | attribute labels (name => label) |
public attributes ( ) : array | ||
리턴 | array | list of attribute names. |
public beforeValidate ( ) : boolean | ||
리턴 | boolean | whether the validation should be executed. Defaults to true. If false is returned, the validation will stop and the model is considered invalid. |
public clearErrors ( string $attribute = null ) | ||
$attribute | string | attribute name. Use null to remove errors for all attributes. |
public createValidators ( ) : ArrayObject | ||
리턴 | ArrayObject | validators |
public generateAttributeLabel ( string $name ) : string | ||
$name | string | the column name |
리턴 | string | the attribute label |
public getActiveValidators ( string $attribute = null ) : |
||
$attribute | string | the name of the attribute whose applicable validators should be returned. If this is null, the validators for ALL attributes in the model will be returned. |
리턴 | the validators applicable to the current [[scenario]]. |
public getAttributeHint ( string $attribute ) : string | ||
$attribute | string | the attribute name |
리턴 | string | the attribute hint |
public getAttributeLabel ( string $attribute ) : string | ||
$attribute | string | the attribute name |
리턴 | string | the attribute label |
public getAttributes ( array $names = null, array $except = [] ) : array | ||
$names | array | list of attributes whose value needs to be returned. Defaults to null, meaning all attributes listed in [[attributes()]] will be returned. If it is an array, only the attributes in the array will be returned. |
$except | array | list of attributes whose value should NOT be returned. |
리턴 | array | attribute values (name => value). |
public getErrors ( string $attribute = null ) : array | ||
$attribute | string | attribute name. Use null to retrieve errors for all attributes. |
리턴 | array | errors for all attributes or the specified attribute. Empty array is returned if no error. Note that when returning errors for all attributes, the result is a two-dimensional array, like the following: ```php [ 'username' => [ 'Username is required.', 'Username must contain only word characters.', ], 'email' => [ 'Email address is invalid.', ] ] ``` |
public getFirstError ( string $attribute ) : string | ||
$attribute | string | attribute name. |
리턴 | string | the error message. Null is returned if no error. |
public getFirstErrors ( ) : array | ||
리턴 | array | the first errors. The array keys are the attribute names, and the array values are the corresponding error messages. An empty array will be returned if there is no error. |
public getIterator ( ) : ArrayIterator | ||
리턴 | ArrayIterator | an iterator for traversing the items in the list. |
public getScenario ( ) : string | ||
리턴 | string | the scenario that this model is in. Defaults to [[SCENARIO_DEFAULT]]. |
public getValidators ( ) : ArrayObjec\ArrayObject | |
||
리턴 | ArrayObjec\ArrayObject | |
all the validators declared in the model. |
public isAttributeActive ( string $attribute ) : boolean | ||
$attribute | string | attribute name |
리턴 | boolean | whether the attribute is active in the current scenario |
public isAttributeRequired ( string $attribute ) : boolean | ||
$attribute | string | attribute name |
리턴 | boolean | whether the attribute is required |
public isAttributeSafe ( string $attribute ) : boolean | ||
$attribute | string | attribute name |
리턴 | boolean | whether the attribute is safe for massive assignments |
public load ( array $data, string $formName = null ) : boolean | ||
$data | array | the data array to load, typically `$_POST` or `$_GET`. |
$formName | string | the form name to use to load the data into the model. If not set, [[formName()]] is used. |
리턴 | boolean | whether `load()` found the expected form in `$data`. |
public static loadMultiple ( array $models, array $data, string $formName = null ) : boolean | ||
$models | array | the models to be populated. Note that all models should have the same class. |
$data | array | the data array. This is usually `$_POST` or `$_GET`, but can also be any valid array supplied by end user. |
$formName | string | the form name to be used for loading the data into the models. If not set, it will use the [[formName()]] value of the first model in `$models`. This parameter is available since version 2.0.1. |
리턴 | boolean | whether at least one of the models is successfully populated. |
public offsetExists ( mixed $offset ) : boolean | ||
$offset | mixed | the offset to check on. |
리턴 | boolean | whether or not an offset exists. |
public offsetUnset ( mixed $offset ) | ||
$offset | mixed | the offset to unset element |
public onUnsafeAttribute ( string $name, mixed $value ) | ||
$name | string | the unsafe attribute name |
$value | mixed | the attribute value |
public safeAttributes ( ) : string[] | ||
리턴 | string[] | safe attribute names |
public setAttributes ( array $values, boolean $safeOnly = true ) | ||
$values | array | attribute values (name => value) to be assigned to the model. |
$safeOnly | boolean | whether the assignments should only be done to the safe attributes. A safe attribute is one that is associated with a validation rule in the current [[scenario]]. |
public setScenario ( string $value ) | ||
$value | string | the scenario that this model is in. |
public validate ( array $attributeNames = null, boolean $clearErrors = true ) : boolean | ||
$attributeNames | array | list of attribute names that should be validated. If this parameter is empty, it means any attribute listed in the applicable validation rules should be validated. |
$clearErrors | boolean | whether to call [[clearErrors()]] before performing validation |
리턴 | boolean | whether the validation is successful without any error. |
public static validateMultiple ( array $models, array $attributeNames = null ) : boolean | ||
$models | array | the models to be validated |
$attributeNames | array | list of attribute names that should be validated. If this parameter is empty, it means any attribute listed in the applicable validation rules should be validated. |
리턴 | boolean | whether all models are valid. False will be returned if one or multiple models have validation error. |