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