本文整理汇总了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;
}