本文整理汇总了PHP中ActiveRecord::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::validate方法的具体用法?PHP ActiveRecord::validate怎么用?PHP ActiveRecord::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::validate方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
*
* @return array|string
*/
public function run()
{
$data = $this->requestMethod === 'post' ? Yii::$app->getRequest()->post('Article') : Yii::$app->getRequest()->get('Article');
$this->model->setAttributes($data);
$this->model->validate();
if ($this->controller === null) {
return ['view' => $this->view, 'model' => $this->model];
} else {
return $this->controller->renderPartial($this->view, ['model' => $this->model]);
}
}
示例2: validate
public function validate($deep = true)
{
parent::validate($deep);
if (!$this->KeyID == !$this->IP) {
$this->_validator->addError('Ban', 'Ban must specifiy either a API key or an IP address');
}
return $this->finishValidation();
}
示例3: validate
public function validate()
{
// call parent
parent::validate();
$this->_validator->validate(array('field' => 'Email', 'validator' => 'email'));
// save results
return $this->finishValidation();
}
示例4: validate
public function validate($deep = true)
{
// call parent
parent::validate($deep);
$this->_validator->validate(array('field' => 'CategoryID', 'validator' => 'number'));
$this->_validator->validate(array('field' => 'ContextClass', 'validator' => 'className'));
$this->_validator->validate(array('field' => 'ContextID', 'validator' => 'number'));
// save results
$this->_isValid = $this->_isValid && !$this->_validator->hasErrors();
if (!$this->_isValid) {
$this->_validationErrors = array_merge($this->_validationErrors, $this->_validator->getErrors());
}
return $this->_isValid;
}
示例5: validate
public function validate($deep = true)
{
// call parent
parent::validate($deep);
// check handle uniqueness
if ($this->isFieldDirty('Code') && !$this->_validator->hasErrors('Code') && $this->Code) {
$ExistingRecord = static::getByHandle($this->Code);
if ($ExistingRecord && $ExistingRecord->ID != $this->ID) {
$this->_validator->addError('Code', 'Code already registered');
}
}
// save results
return $this->finishValidation();
}
示例6: validate
public function validate($deep = true)
{
parent::validate($deep);
HandleBehavior::onValidate($this, $this->_validator);
// check if URL has already been posted in this project
if ($this->isFieldDirty('URL') && !$this->_validator->hasErrors('URL') && $this->URL && $this->ProjectID) {
$duplicateConditions = ['ProjectID' => $this->ProjectID, 'URL' => $this->URL];
if ($this->ID) {
$duplicateConditions[] = sprintf('ID != %u', $this->ID);
}
if ($this::getByWhere($duplicateConditions)) {
$this->_validator->addError('URL', _('This URL has already been logged as buzz for this project'));
}
}
return $this->finishValidation();
}
示例7: validate
public function validate($deep = true)
{
// call parent
parent::validate($deep);
$this->_validator->validate(array('field' => 'Type', 'validator' => 'selection', 'choices' => self::$fields['Type']['values'], 'required' => false));
$this->_validator->validate(array('field' => 'Handle', 'required' => false, 'validator' => 'handle', 'errorMessage' => 'URL handle can only contain letters, numbers, hyphens, and underscores'));
if ($this->Type == 'Alias' && (!$this->Context || !is_a($this->Context, 'ActiveRecord'))) {
$this->_validator->addError('Context', 'Context required to create alias handle');
}
// check handle uniqueness
if ($this->isDirty && !$this->_validator->hasErrors('Handle') && $this->Handle) {
$ExistingRecord = static::getByHandle($this->Handle);
if ($ExistingRecord && $ExistingRecord->ID != $this->ID) {
$this->_validator->addError('Handle', 'URL already registered');
}
}
// save results
return $this->finishValidation();
}
示例8: validate
public function validate($deep = true)
{
// call parent
parent::validate($deep);
$this->_validator->validate(array('field' => 'Name'));
$this->_validator->validate(array('field' => 'Address', 'validator' => 'address'));
$this->_validator->validate(array('field' => 'Address2', 'required' => false));
$this->_validator->validate(array('field' => 'City'));
$this->_validator->validate(array('field' => 'Country', 'validator' => 'selection', 'choices' => static::getFieldOptions('Country', 'values')));
if (!$this->_validator->hasErrors('Country')) {
$this->_validator->validate(array('field' => 'State_Province', 'validator' => 'state_province', 'country' => $this->Country));
$this->_validator->validate(array('field' => 'Zip_Postal', 'validator' => 'zip_postal', 'country' => $this->Country));
$this->_validator->validate(array('field' => 'Phone', 'validator' => 'phone', 'country' => $this->Country, 'required' => static::$requirePhone));
}
// save results
$this->_isValid = $this->_isValid && !$this->_validator->hasErrors();
if (!$this->_isValid) {
$this->_validationErrors = array_merge($this->_validationErrors, $this->_validator->getErrors());
}
return $this->_isValid;
}
示例9: validate
public function validate($attributes = null, $clearErrors = true)
{
if ($this->EntranceTypeID == 1) {
$this->scenario = "ZNO";
}
if ($this->EntranceTypeID == 2) {
$this->scenario = "EXAM";
}
if ($this->EntranceTypeID == 3) {
$this->scenario = "ZNOEXAM";
}
return parent::validate($attributes, $clearErrors);
}
示例10: validate
public function validate($deep = true)
{
// call parent
parent::validate();
$this->_validator->validate(array('field' => 'Title'));
// check title uniqueness
if ($this->isDirty && !$this->_validator->hasErrors('Title') && $this->Title) {
$ExistingTag = Tag::getByTitle($this->Title);
if ($ExistingTag && $ExistingTag->ID != $this->ID) {
$this->_validator->addError('Title', 'A tag by this title already exists');
}
// Existing handle
$ExistingHandle = Tag::getByHandle($this->Handle);
if ($ExistingHandle && $ExistingHandle->ID != $this->ID) {
$this->_validator->addError('Handle', 'A tag by this handle already exists');
}
}
// save results
return $this->finishValidation();
}