/** * server validatiom for unique zip_code * @param \yii\base\Model $model * @param string $attribute */ public function validateAttribute($model, $attribute) { $value = $model->{$attribute}; if (!Locations::find()->where(['zip_code' => $value])->exists()) { $model->addError($attribute, $this->message); } }
public static function checkRequiredParams($params, $required_params) { $missing_parameters = self::allTheRequiredParametersAre($params, $required_params); $model = new Model(); if ($missing_parameters) { $model->addError("this parameters are missing ", $error = implode(", ", $missing_parameters)); } return $model; }
/** * Adds an error about the specified attribute to the model object. * This is a helper method that performs message selection and internationalization. * @param \yii\base\Model $model the data model being validated * @param string $attribute the attribute being validated * @param string $message the error message * @param array $params values for the placeholders in the error message */ public function addError($model, $attribute, $message, $params = []) { $params['attribute'] = $model->getAttributeLabel($attribute); if (!isset($params['value'])) { $value = $model->{$attribute}; if (is_array($value)) { $params['value'] = 'array()'; } elseif (is_object($value) && !method_exists($value, '__toString')) { $params['value'] = '(object)'; } else { $params['value'] = $value; } } $model->addError($attribute, Yii::$app->getI18n()->format($message, $params, Yii::$app->language)); }
/** * Adds an error about the specified attribute to the model object. * This is a helper method that performs message selection and internationalization. * @param \yii\base\Model $object the data object being validated * @param string $attribute the attribute being validated * @param string $message the error message * @param array $params values for the placeholders in the error message */ public function addError($object, $attribute, $message, $params = []) { $value = $object->{$attribute}; $params['attribute'] = $object->getAttributeLabel($attribute); $params['value'] = is_array($value) ? 'array()' : $value; $object->addError($attribute, Yii::$app->getI18n()->format($message, $params, Yii::$app->language)); }
/** * Adds an error about the specified attribute to the model object. * This is a helper method that performs message selection and internationalization. * @param \yii\base\Model $model the data model being validated * @param string $attribute the attribute being validated * @param string $message the error message * @param array $params values for the placeholders in the error message */ public function addError($model, $attribute, $message, $params = []) { $params['attribute'] = $model->getAttributeLabel($attribute); if (!isset($params['value'])) { $value = $model->{$attribute}; $params['value'] = is_array($value) ? 'array()' : $value; } $model->addError($attribute, Yii::$app->getI18n()->format($message, $params, Yii::$app->language)); }