当前位置: 首页>>代码示例>>PHP>>正文


PHP BaseModel::validate方法代码示例

本文整理汇总了PHP中BaseModel::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP BaseModel::validate方法的具体用法?PHP BaseModel::validate怎么用?PHP BaseModel::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BaseModel的用法示例。


在下文中一共展示了BaseModel::validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validate

 /**
  * @param null $attributes
  * @param bool $clearErrors
  * @return bool|void
  */
 public function validate($attributes = null, $clearErrors = true)
 {
     //ClearErrors?
     if ($clearErrors) {
         $this->clearErrors();
     }
     //Any recipients specified?
     if ($this->sendto_usergroups == false && $this->sendto_users == false) {
         $this->addError('sendto', Craft::t('No recipients specified'));
     }
     //UserGroup recipients
     if ($this->sendto_usergroups) {
         if (!$this->usergroups) {
             $this->addError('usergroups', Craft::t('No usergroups specified'));
         } elseif (array_filter($this->usergroups, 'is_int') === $this->usergroups) {
             $this->addError('usergroups', Craft::t('Invalid usergroups specified'));
         }
     }
     //User recipients
     if ($this->sendto_users) {
         if (!$this->users) {
             $this->addError('users', Craft::t('No users specified'));
         } elseif (array_filter($this->users, 'is_int') === $this->users) {
             $this->addError('users', Craft::t('Invalid users specified'));
         }
     }
     //Return
     return parent::validate($attributes, false);
 }
开发者ID:webremote,项目名称:Craft-Mailer,代码行数:34,代码来源:Mailer_ExportModel.php

示例2: validate

 public function validate($attributes = null, $clearErrors = true)
 {
     parent::validate($attributes, $clearErrors);
     if (is_array($this->types)) {
         if (in_array('entry', $this->types) && $this->entrySources == '') {
             $this->addError('entrySources', Craft::t('Please select at least 1 entry source.'));
         }
         if (in_array('asset', $this->types) && $this->assetSources == '') {
             $this->addError('assetSources', Craft::t('Please select at least 1 asset source.'));
         }
         if (in_array('category', $this->types) && $this->categorySources == '') {
             $this->addError('categorySources', Craft::t('Please select at least 1 category source.'));
         }
         if (in_array('product', $this->types) && $this->productSources == '') {
             $this->addError('productSources', Craft::t('Please select at least 1 product source.'));
         }
         // Handle third party element errors
         $thirdPartyElementTypes = craft()->fruitLinkIt->getThirdPartyElementTypes();
         foreach ($thirdPartyElementTypes as $elementTypeHandle => $elementTypeConfig) {
             if (in_array($elementTypeHandle, $this->types) && $this[$elementTypeHandle . 'Sources'] == '') {
                 $this->addError($elementTypeHandle . 'Sources', Craft::t('Please select at least 1 ' . strtolower($elementTypeConfig['name']) . ' source.'));
             }
         }
     } else {
         $this->addError('types', Craft::t('Please select at least 1 link type.'));
     }
     return !$this->hasErrors();
 }
开发者ID:transomdesign,项目名称:transom-craft-starter,代码行数:28,代码来源:FruitLinkIt_LinkSettingsModel.php

示例3: validate

 /**
  * Validates the custom fields.
  *
  * @param array|null $attributes
  * @param bool       $clearErrors
  *
  * @return bool
  */
 public function validate($attributes = null, $clearErrors = true)
 {
     $validates = parent::validate($attributes, $clearErrors);
     foreach (craft()->fields->getAllFields() as $field) {
         $handle = $field->handle;
         if (is_array($attributes) && !in_array($handle, $attributes)) {
             continue;
         }
         $value = $this->getAttribute($handle);
         // Don't worry about blank values. Those will already be caught by required field validation.
         if ($value) {
             $fieldType = $field->getFieldType();
             if ($fieldType) {
                 $errors = $fieldType->validate($value);
                 if ($errors !== true) {
                     if (is_string($errors)) {
                         $this->addError($handle, $errors);
                     } else {
                         if (is_array($errors)) {
                             foreach ($errors as $error) {
                                 $this->addError($handle, $error);
                             }
                         }
                     }
                     $validates = false;
                 }
             }
         }
     }
     return $validates;
 }
开发者ID:blairrorani,项目名称:everlearning,代码行数:39,代码来源:ContentModel.php

示例4: validate

 /**
  * Validates all of the attributes for the current Model. Any attributes that fail validation will additionally get
  * logged to the `craft/storage/runtime/logs` folder with a level of LogLevel::Warning.
  *
  * In addition, we check that the username does not have any whitespace in it.
  *
  * @param null $attributes
  * @param bool $clearErrors
  *
  * @return bool|null
  */
 public function validate($attributes = null, $clearErrors = true)
 {
     // Don't allow whitespace in the username.
     if (preg_match('/\\s+/', $this->username)) {
         $this->addError('username', Craft::t('Spaces are not allowed in the username.'));
     }
     return parent::validate($attributes, false);
 }
开发者ID:jmstan,项目名称:craft-website,代码行数:19,代码来源:UsernameModel.php

示例5: validate

 /**
  * Add custom validation rules to routine.
  *
  * @param Array $attributes
  * @param Bool $clearErrors
  * @return Bool
  */
 public function validate($attributes = null, $clearErrors = true)
 {
     if ($clearErrors) {
         $this->clearErrors();
     }
     $this->validateCachePathAndUrl();
     return parent::validate($attributes, false);
 }
开发者ID:speder,项目名称:craft.minimee,代码行数:15,代码来源:Minimee_SettingsModel.php

示例6: getTranslatedDefinition

 /**
  * Returns the translated definition for the word hatred
  *
  * {Injects a static method dependency for Craft::t}
  *
  * @param	string	$translator	The name of the static class that defines t()
  *
  * @return	string
  */
 public function getTranslatedDefinition(BaseModel $model)
 {
     if ($model->validate()) {
         // Static method dependencies are just not elegant to work with
         // We can use $model->property but using $model->getAttribute('property') make this method more testable
         return call_user_func_array($this->translator . '::t', array($model->getAttribute('definition')));
     }
     return false;
 }
开发者ID:webremote,项目名称:craft.loath,代码行数:18,代码来源:LoathService.php

示例7: validate

 public function validate($attributes = null, $clearErrors = true)
 {
     // Enforce $clearErrors without copying code if we don't have to
     $validates = parent::validate($attributes, $clearErrors);
     if (!craft()->superTable->validateFieldSettings($this)) {
         $validates = false;
     }
     return $validates;
 }
开发者ID:GianlucaGuarini,项目名称:SuperTable,代码行数:9,代码来源:SuperTable_SettingsModel.php

示例8: validate

 /**
  * Throws exceptions for validation errors when in devMode.
  *
  * @return bool
  */
 public function validate($attributes = null, $clearErrors = true)
 {
     $validate = parent::validate($attributes, $clearErrors);
     if (!$validate && craft()->config->get('devMode')) {
         foreach ($this->getAllErrors() as $attribute => $error) {
             throw new Exception(Craft::t($error));
         }
     }
     return $validate;
 }
开发者ID:amite,项目名称:arc-va,代码行数:15,代码来源:Sitemap_BaseModel.php

示例9: validate

 public function validate($model = null)
 {
     if (parent::validate()) {
         if (is_object(static::buscar($this->formulario, $this->campo)) && !isset($this->id)) {
             $this->errors->add('formulario', 'El formulario debe ser unico');
         }
         return !$this->hasErrors();
     }
     return false;
 }
开发者ID:richarrieta,项目名称:miequipo,代码行数:10,代码来源:AyudaCampo.php

示例10: validate

 public function validate($attributes = null, $clearErrors = true)
 {
     $arr = explode("/", $this->birth);
     if (count($arr) != 3) {
         $this->addError('birth', Craft::t('Incorrect date format, please use DD/MM/YY date format'));
     } else {
         if (strlen($arr[0]) != 2 || $arr[0] < 1 || $arr[0] > 31 || strlen($arr[1]) != 2 || $arr[1] < 1 || $arr[1] > 12 || strlen($arr[2]) != 2 || $arr[2] < 96 && $arr[2] > 14 || $arr[2] < 0) {
             $this->addError('birth', Craft::t('Incorrect date format, please use DD/MM/YY date format'));
         }
     }
     return parent::validate($attributes, false);
 }
开发者ID:JameelJiwani,项目名称:TeamManager_Plugin,代码行数:12,代码来源:TeamManager_PlayerModel.php

示例11: validate

 /**
  * @param null $attributes
  * @param bool $clearErrors
  * @return bool|void
  */
 public function validate($attributes = null, $clearErrors = true)
 {
     parent::validate($attributes, $clearErrors);
     if ($this->yearRangeStart) {
         if (!is_numeric($this->yearRangeStart) && strtotime($this->yearRangeStart) === false) {
             $this->addError('yearRangeStart', Craft::t('Not a valid value, use a full year notation or a strtotime() value.'));
         }
     }
     if ($this->yearRangeEnd) {
         if (!is_numeric($this->yearRangeEnd) && strtotime($this->yearRangeEnd) === false) {
             $this->addError('yearRangeEnd', Craft::t('Not a valid value, use a full year notation or a strtotime() value.'));
         }
     }
     return !$this->hasErrors();
 }
开发者ID:ctigelaar,项目名称:craft-dropdowndate,代码行数:20,代码来源:DropDownDate_DateInputModel.php

示例12: validate

 /**
  * @param null $attributes
  * @param bool $clearErrors
  * @return bool|void
  */
 public function validate($attributes = null, $clearErrors = true)
 {
     //ClearErrors?
     if ($clearErrors) {
         $this->clearErrors();
     }
     //Mail RegEx
     $regex = '/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})$/i';
     //Any Recipient specified?
     if (empty($this->recipients)) {
         $this->addError('recipients', Craft::t('No recipients specified'));
     } else {
         //Check each array
         foreach ($this->recipients as $array) {
             //To (required)
             /*$to_emails = preg_split('[,]', $array['to']);
             
             				foreach($to_emails as $mail) {
             					if (preg_match( $regex, trim($mail) ) == 0) {
             						$this->addError('to', trim($mail) . Craft::t(' is not a valid email'));
             					}
             				}*/
             if (preg_match($regex, $array['to']) == 0) {
                 $this->addError('to', $array['to'] . Craft::t(' is not a valid email'));
             }
             //Currently only one 'to' address is allowed.
             //CC (optional)
             if (!empty($array['cc'])) {
                 $cc_emails = preg_split('[,]', $array['cc']);
                 foreach ($cc_emails as $mail) {
                     if (preg_match($regex, trim($mail)) == 0) {
                         $this->addError('cc', trim($mail) . Craft::t(' is not a valid email'));
                     }
                 }
             }
             //BCC (optional)
             if (!empty($array['bcc'])) {
                 $bcc_emails = preg_split('[,]', $array['bcc']);
                 foreach ($bcc_emails as $mail) {
                     if (preg_match($regex, trim($mail)) == 0) {
                         $this->addError('bcc', trim($mail) . Craft::t(' is not a valid email'));
                     }
                 }
             }
         }
     }
     return parent::validate($attributes, false);
 }
开发者ID:webremote,项目名称:Craft-Mailer,代码行数:53,代码来源:Mailer_RecipientsModel.php

示例13: validate

 public function validate($attributes = null, $clearErrors = true)
 {
     parent::validate($attributes, $clearErrors);
     if (is_array($this->types)) {
         if (in_array('entry', $this->types) && $this->entrySources == '') {
             $this->addError('entrySources', Craft::t('Please select at least 1 entry source.'));
         }
         if (in_array('asset', $this->types) && $this->assetSources == '') {
             $this->addError('assetSources', Craft::t('Please select at least 1 asset source.'));
         }
         if (in_array('category', $this->types) && $this->categorySources == '') {
             $this->addError('categorySources', Craft::t('Please select at least 1 category source.'));
         }
         if (in_array('product', $this->types) && $this->productSources == '') {
             $this->addError('productSources', Craft::t('Please select at least 1 product source.'));
         }
     } else {
         $this->addError('types', Craft::t('Please select at least 1 link type.'));
     }
     return !$this->hasErrors();
 }
开发者ID:mrpaulphan,项目名称:mrpaulphan,代码行数:21,代码来源:FruitLinkIt_LinkSettingsModel.php

示例14: validate

 /**
  * @param null $attributes
  * @param bool $clearErrors
  * @return bool|void
  */
 public function validate($attributes = null, $clearErrors = true)
 {
     // Don't allow whitespace in the code.
     /*  if (preg_match('/\s+/', $this->code)) {
             $this->addError('code', Craft::t('Spaces are not allowed in the coupon code.'));
         }*/
     if ($this->couponType == 'percentage' and $this->percentageOff == '') {
         $this->addError('percentageOff', Craft::t('Percentage Off is required'));
     }
     if ($this->couponType == 'amount' and $this->amountOff == '') {
         $this->addError('amountOff', Craft::t('Amount Off is required'));
     }
     if ($this->couponType == 'amount' and $this->amountOff == '') {
         $this->addError('amountOff', Craft::t('Amount Off is required'));
     }
     if ($this->couponType == 'amount' and $this->amountOff == '0') {
         $this->addError('amountOff', Craft::t('Amount Off must be more than 0'));
     }
     if ($this->duration == 'repeating' and ($this->durationInMonths == '' or $this->durationInMonths == '0')) {
         $this->addError('durationInMonths', Craft::t('Duration in Months is required if the Duration is set to \'Repeating\'. Set to \'Forever\' for no limit'));
     }
     return parent::validate($attributes, false);
 }
开发者ID:jamiepittock,项目名称:WhereForArt,代码行数:28,代码来源:Charge_CouponModel.php

示例15: validate

 /**
  * Validates all the attributes, block types and groups.
  *
  * @param array|null $attributes
  * @param bool|true $clearErrors
  * @return bool
  */
 public function validate($attributes = null, $clearErrors = true)
 {
     return parent::validate($attributes, $clearErrors) && craft()->neo->validateFieldSettings($this);
 }
开发者ID:benjamminf,项目名称:craft-neo,代码行数:11,代码来源:Neo_SettingsModel.php


注:本文中的BaseModel::validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。