本文整理匯總了PHP中CModel::clearErrors方法的典型用法代碼示例。如果您正苦於以下問題:PHP CModel::clearErrors方法的具體用法?PHP CModel::clearErrors怎麽用?PHP CModel::clearErrors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CModel
的用法示例。
在下文中一共展示了CModel::clearErrors方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: generateModelErrorFields
/**
* @param \CModel $model
* @param null $path
* @return array
*/
public function generateModelErrorFields(\CModel $model, $path = null)
{
$validators = \CValidator::$builtInValidators;
if ($this->hasEventHandler('onBeforeGenerateError')) {
$this->onBeforeGenerateError(new \CEvent($this, array('model' => $model)));
}
$errors = $model->getErrors();
$errorFields = array_keys($errors);
$errorHandled = array();
$i = 0;
$result = array();
foreach ($model->getValidators() as $validator) {
if (isset($hasError) && $validator->skipOnError || !array_intersect($validator->attributes, $errorFields)) {
continue;
}
$model->clearErrors();
$validator->validate($model);
if ($model->hasErrors()) {
$hasError = true;
$code = array_search(get_class($validator), $validators);
if ($validator instanceof \CInlineValidator) {
$code = $validator->method;
}
foreach ($validator->attributes as $attribute) {
if ($model->hasErrors($attribute)) {
$result[$i]['code'] = $code;
$result[$i]['message'] = $model->getError($attribute);
$result[$i]['name'] = $path ? $path . '[' . $attribute . ']' : $attribute;
$errorHandled[] = $attribute;
$i++;
}
}
}
}
foreach (array_diff($errorFields, $errorHandled) as $attribute) {
$result[$i]['code'] = 'unknown';
$result[$i]['message'] = implode(',', $errors[$attribute]);
$result[$i]['name'] = $path ? $path . '[' . $attribute . ']' : $attribute;
}
return $result;
}
示例2: _generateModelErrorFields
/**
* @param \CModel $model
* @return array
*/
protected function _generateModelErrorFields(\CModel $model)
{
$validators = \CValidator::$builtInValidators;
$errors = $model->getErrors();
$errorFields = array_keys($errors);
$errorHandled = array();
$i = 0;
$result = array();
foreach ($model->getValidators() as $validator) {
if (isset($hasError) && $validator->skipOnError || !array_intersect($validator->attributes, $errorFields)) {
continue;
}
$model->clearErrors();
$validator->validate($model);
if ($model->hasErrors()) {
$hasError = true;
$code = array_search(get_class($validator), $validators);
if ($validator instanceof \CInlineValidator) {
$code = $validator->method;
}
foreach ($validator->attributes as $attribute) {
if ($model->hasErrors($attribute)) {
$result[$i]['code'] = $code;
$result[$i]['message'] = $model->getError($attribute);
$result[$i]['name'] = $attribute;
$errorHandled[] = $attribute;
$i++;
}
}
}
}
foreach (array_diff($errorFields, $errorHandled) as $attribute) {
$result[$i]['code'] = 'unknown';
$result[$i]['message'] = implode(',', $errors[$attribute]);
$result[$i]['name'] = $attribute;
}
return $result;
}