當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。