Class yii\validators\InlineValidator
Inheritance | yii\validators\InlineValidator » yii\validators\Validator » yii\base\Component » yii\base\Object |
---|---|
Implements | yii\base\Configurable |
Available since version | 2.0 |
Source Code | https://github.com/yiisoft/yii2/blob/master/framework/validators/InlineValidator.php |
InlineValidator represents a validator which is defined as a method in the object being validated.
The validation method must have the following signature:
function foo($attribute, $params)
where $attribute
refers to the name of the attribute being validated, while $params
is an array representing the additional parameters supplied in the validation rule.
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$attributes | array|string | Attributes to be validated by this validator. | yii\validators\Validator |
$behaviors | yii\base\Behavior[] | List of behaviors attached to this component | yii\base\Component |
$builtInValidators | array | List of built-in validators (name => class or configuration) | yii\validators\Validator |
$clientValidate | string|Closure | An anonymous function or the name of a model class method that returns the client validation code. | yii\validators\InlineValidator |
$enableClientValidation | boolean | Whether to enable client-side validation for this validator. | yii\validators\Validator |
$except | array|string | Scenarios that the validator should not be applied to. | yii\validators\Validator |
$isEmpty | callable | A PHP callable that replaces the default implementation of isEmpty(). | yii\validators\Validator |
$message | string | The user-defined error message. | yii\validators\Validator |
$method | string|Closure | An anonymous function or the name of a model class method that will be called to perform the actual validation. | yii\validators\InlineValidator |
$on | array|string | Scenarios that the validator can be applied to. | yii\validators\Validator |
$params | mixed | Additional parameters that are passed to the validation method | yii\validators\InlineValidator |
$skipOnEmpty | boolean | Whether this validation rule should be skipped if the attribute value is null or an empty string. | yii\validators\Validator |
$skipOnError | boolean | Whether this validation rule should be skipped if the attribute being validated already has some validation error according to some previous rules. | yii\validators\Validator |
$when | callable | A PHP callable whose return value determines whether this validator should be applied. | yii\validators\Validator |
$whenClient | string | A JavaScript function name whose return value determines whether this validator should be applied on the client side. | yii\validators\Validator |
Public Methods
Method | Description | Defined By |
---|---|---|
__call() | Calls the named method which is not a class method. | yii\base\Component |
__clone() | This method is called after the object is created by cloning an existing one. | yii\base\Component |
__construct() | Constructor. | yii\base\Object |
__get() | Returns the value of a component property. | yii\base\Component |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\base\Component |
__set() | Sets the value of a component property. | yii\base\Component |
__unset() | Sets a component property to be null. | yii\base\Component |
addError() | Adds an error about the specified attribute to the model object. | yii\validators\Validator |
attachBehavior() | Attaches a behavior to this component. | yii\base\Component |
attachBehaviors() | Attaches a list of behaviors to the component. | yii\base\Component |
behaviors() | Returns a list of behaviors that this component should behave as. | yii\base\Component |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\base\Component |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\base\Component |
className() | Returns the fully qualified name of this class. | yii\base\Object |
clientValidateAttribute() | Returns the JavaScript needed for performing client-side validation. | yii\validators\InlineValidator |
createValidator() | Creates a validator object. | yii\validators\Validator |
detachBehavior() | Detaches a behavior from the component. | yii\base\Component |
detachBehaviors() | Detaches all behaviors from the component. | yii\base\Component |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\base\Component |
getBehavior() | Returns the named behavior object. | yii\base\Component |
getBehaviors() | Returns all behaviors attached to this component. | yii\base\Component |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. | yii\base\Component |
hasMethod() | Returns a value indicating whether a method is defined. | yii\base\Component |
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\base\Component |
init() | Initializes the object. | yii\base\Object |
isActive() | Returns a value indicating whether the validator is active for the given scenario and attribute. | yii\validators\Validator |
isEmpty() | Checks if the given value is empty. | yii\validators\Validator |
off() | Detaches an existing event handler from this component. | yii\base\Component |
on() | Attaches an event handler to an event. | yii\base\Component |
trigger() | Triggers an event. | yii\base\Component |
validate() | Validates a given value. | yii\validators\Validator |
validateAttribute() | Validates a single attribute. | yii\validators\InlineValidator |
validateAttributes() | Validates the specified object. | yii\validators\Validator |
Protected Methods
Method | Description | Defined By |
---|---|---|
validateValue() | Validates a value. | yii\validators\Validator |
Property Details
An anonymous function or the name of a model class method that returns the client validation code. The signature of the method should be like the following:
function foo($attribute, $params)
{
return "javascript";
}
where $attribute
refers to the attribute name to be validated.
Please refer to clientValidateAttribute() for details on how to return client validation code.
An anonymous function or the name of a model class method that will be
called to perform the actual validation. The signature of the method should be like the following,
where $attribute
is the name of the attribute to be validated, and $params
contains the value
of $params that you specify when declaring the inline validation rule:
function foo($attribute, $params)
Additional parameters that are passed to the validation method
Method Details
Returns the JavaScript needed for performing client-side validation.
You may override this method to return the JavaScript validation code if the validator can support client-side validation.
The following JavaScript variables are predefined and can be used in the validation code:
attribute
: the name of the attribute being validated.value
: the value being validated.messages
: an array used to hold the validation error messages for the attribute.deferred
: an array used to hold deferred objects for asynchronous validation
string clientValidateAttribute( $model, $attribute, $view ) | ||
$model | yii\base\Model | The data model being validated |
$attribute | string | The name of the attribute to be validated. |
$view | yii\web\View | The view object that is going to be used to render views or view files containing a model form with this validator applied. |
return | string | The client-side validation script. Null if the validator does not support client-side validation. |
---|
Validates a single attribute.
Child classes must implement this method to provide the actual validation logic.
void validateAttribute( $model, $attribute ) | ||
$model | yii\base\Model | The data model to be validated |
$attribute | string | The name of the attribute to be validated. |