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


PHP Gdn_Model::validate方法代码示例

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


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

示例1: validate

 /**
  * Do validation on addon data.
  *
  * @param array $Post
  * @param bool $Insert
  * @return bool
  */
 public function validate($Post, $Insert = false)
 {
     $this->Validation->addRule('AddonKey', 'function:ValidateAddonKey');
     if (val('Checked', $Post) && ($Insert || isset($Post['AddonKey']))) {
         $this->Validation->applyRule('AddonKey', 'Required');
         $this->Validation->applyRule('AddonKey', 'AddonKey');
     }
     if ($Insert || isset($Post['Version'])) {
         $this->Validation->applyRule('Version', 'Required');
         $this->Validation->applyRule('Version', 'Version');
     }
     parent::validate($Post, $Insert);
     // Validate against an existing addon.
     if ($AddonID = val('AddonID', $Post)) {
         $CurrentAddon = $this->getID($AddonID, false, ['GetVersions' => true]);
         if ($CurrentAddon) {
             if (val('AddonKey', $CurrentAddon) && isset($Post['AddonKey']) && val('AddonKey', $Post) != val('AddonKey', $CurrentAddon)) {
                 $this->Validation->addValidationResult('AddonKey', '@' . sprintf(t('The addon\'s key cannot be changed. The uploaded file has a key of <b>%s</b>, but it must be <b>%s</b>.'), val('AddonKey', $Post), val('AddonKey', $CurrentAddon)));
             } else {
                 // Make sure this version doesn't match.
                 foreach ($CurrentAddon['Versions'] as $Version) {
                     if ($Version['Deleted']) {
                         continue;
                     }
                     if (version_compare(val('Version', $Version), val('Version', $Post)) == 0) {
                         // This version matches a previous version.
                         if (val('Checked', $Version) && val('MD5', $Version) != val('MD5', $Post)) {
                             $this->Validation->addValidationResult('Version', '@' . sprintf(t('Version %s of this addon already exists.'), val('Version', $Version)));
                         }
                     }
                 }
             }
         }
     }
     trace($Post, 'PostValidate');
     // Make sure there isn't another addon with the same key as this one.
     if (validateRequired(val('AddonKey', $Post))) {
         $CountSame = $this->getCount(array('AddonKey' => $Post['AddonKey'], 'AddonID <>' => val('AddonID', $Post), 'a.AddonTypeID' => val('AddonTypeID', $Post)));
         if ($CountSame > 0) {
             $this->Validation->addValidationResult('AddonKey', '@' . sprintf(t('The addon key %s is already taken.'), $Post['AddonKey']));
         }
     }
     return count($this->Validation->results()) == 0;
 }
开发者ID:vanilla,项目名称:community,代码行数:51,代码来源:class.addonmodel.php


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