當前位置: 首頁>>代碼示例>>PHP>>正文


PHP X2Model::addError方法代碼示例

本文整理匯總了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;
 }
開發者ID:dsyman2,項目名稱:X2CRM,代碼行數:62,代碼來源:ImportExportBehavior.php


注:本文中的X2Model::addError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。