本文整理匯總了PHP中X2Model::addError方法的典型用法代碼示例。如果您正苦於以下問題:PHP X2Model::addError方法的具體用法?PHP X2Model::addError怎麽用?PHP X2Model::addError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類X2Model
的用法示例。
在下文中一共展示了X2Model::addError方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: importRecordAttribute
/**
* The import assumes we have human readable data in the CSV and will thus need to convert. This
* method converts link, date, and dateTime fields to the appropriate machine friendly data.
* @param string $modelName The model class being imported
* @param X2Model $model The currently importing model record
* @param string $fieldName Field to set
* @param string $importAttribute Value to set field
* @returns X2Model $model
*/
protected function importRecordAttribute($modelName, X2Model $model, $fieldName, $importAttribute)
{
$fieldRecord = Fields::model()->findByAttributes(array('modelName' => $modelName, 'fieldName' => $fieldName));
// Skip setting the attribute if it has already been set or if the entry from
// the CSV is empty.
if (empty($importAttribute) && ($importAttribute !== 0 && $importAttribute !== '0')) {
return $model;
}
if ($fieldName === 'actionDescription' && $modelName === 'Actions') {
$text = new ActionText();
$text->text = $importAttribute;
if (isset($model->id)) {
$text->actionId = $model->id;
}
$this->setCurrentActionText($text->attributes);
return $model;
}
// ensure the provided id is valid
if (strtolower($fieldName) === 'id' && (!preg_match('/^\\d+$/', $importAttribute) || $importAttribute >= 4294967295)) {
$model->id = $importAttribute;
$model->addError('id', Yii::t('importexport', "ID '{$importAttribute}' is not valid."));
return $model;
}
switch ($fieldRecord->type) {
case "link":
$model = $this->importRecordLinkAttribute($modelName, $model, $fieldRecord, $importAttribute);
break;
case "dateTime":
case "date":
if (Formatter::parseDateTime($importAttribute) !== false) {
$model->{$fieldName} = Formatter::parseDateTime($importAttribute);
}
break;
case "visibility":
switch ($importAttribute) {
case 'Private':
$model->{$fieldName} = 0;
break;
case 'Public':
$model->{$fieldName} = 1;
break;
case 'User\'s Groups':
$model->{$fieldName} = 2;
break;
default:
$model->{$fieldName} = $importAttribute;
}
break;
default:
$model->{$fieldName} = $importAttribute;
}
return $model;
}