Class yii\mongodb\validators\MongoIdValidator
Inheritance | yii\mongodb\validators\MongoIdValidator » yii\validators\Validator |
---|---|
Available since version | 2.0.4 |
MongoIdValidator verifies if the attribute is a valid Mongo ID.
Attribute will be considered as valid, if it is an instance of \MongoId or a its string value.
Usage example:
class Customer extends yii\mongodb\ActiveRecord
{
...
public function rules()
{
return [
['_id', 'yii\mongodb\validators\MongoIdValidator']
];
}
}
This validator may also serve as a filter, allowing conversion of Mongo ID value either to the plain string or to \MongoId instance. You can enable this feature via $forceFormat.
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$forceFormat | string|null | Specifies the format, which validated attribute value should be converted to in case validation was successful. | yii\mongodb\validators\MongoIdValidator |
Public Methods
Method | Description | Defined By |
---|---|---|
init() | yii\mongodb\validators\MongoIdValidator | |
validateAttribute() | yii\mongodb\validators\MongoIdValidator |
Protected Methods
Method | Description | Defined By |
---|---|---|
validateValue() | yii\mongodb\validators\MongoIdValidator |
Property Details
Specifies the format, which validated attribute value should be converted to in case validation was successful. valid values are:
- 'string' - enforce value converted to plain string.
- 'object' - enforce value converted to \MongoId instance. If not set - no conversion will be performed, leaving attribute value intact.
Method Details
public void init ( ) |
public void validateAttribute ( $model, $attribute ) | ||
$model | ||
$attribute |
protected void validateValue ( $value ) | ||
$value |