本文整理汇总了PHP中CModel::getErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP CModel::getErrors方法的具体用法?PHP CModel::getErrors怎么用?PHP CModel::getErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CModel
的用法示例。
在下文中一共展示了CModel::getErrors方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: errorModelSummery
/**
* get error info from model
*
* @param CModel $model
* @return string
* @see CModel
*/
public static function errorModelSummery($model, $attribute = null)
{
if (is_null($attribute)) {
return self::errorSummery($model->getErrors());
} else {
$aryError = $model->getError($attribute, false);
return empty($aryError) ? '' : self::errorSummery(array($aryError));
}
}
示例2: 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;
}
示例3: _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;
}
示例4: getErrors
/**
* Return array of errors on form and model.
* Currently this method does not support specifying the $attributeNameOrNames parameter.
*/
public function getErrors($attributeNameOrNames = null)
{
$formErrors = parent::getErrors($attributeNameOrNames);
$modelErrors = $this->model->getErrors($attributeNameOrNames);
return array_merge($formErrors, $modelErrors);
}