本文整理汇总了PHP中CModel::swValidate方法的典型用法代码示例。如果您正苦于以下问题:PHP CModel::swValidate方法的具体用法?PHP CModel::swValidate怎么用?PHP CModel::swValidate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CModel
的用法示例。
在下文中一共展示了CModel::swValidate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateAttribute
/**
* Validate status change and applies all validators defined by the model for the current transition scenario if
* enableSwValidation is TRUE. If validator parameter 'match' is true, the transition scenario is matched
* against validator scenario (which are assumed to be regular expressions).
*
* @see validators/CValidator::validateAttribute()
* @param CModel $model the model to validate
* @param string $attribute the model attribute to validate
*/
protected function validateAttribute($model, $attribute)
{
$value = $model->{$attribute};
if ($model->swValidate($attribute, $value) == true and $this->enableSwValidation === true) {
$swScenario = $this->_getSWScenarioName($model, $value);
if (!empty($swScenario)) {
if ($this->match === true) {
// validator scenario are Regular Expression that must match the transition scenarion
// for the validator to be executed.
$validators = $model->getValidatorList();
foreach ($validators as $validator) {
if ($this->_validatorMatches($validator, $swScenario)) {
$validator->validate($model);
}
}
} else {
$swScenario = SWValidator::SW_SCENARIO_PREFIX . $swScenario;
// execute only validator defined for the current transition scenario ($swScenario)
// getValidators returns validators with no scenario, and the ones
// that apply to the current scenario (swScenario).
$saveScenario = $model->getScenario();
$model->setScenario($swScenario);
$validators = $model->getValidators();
foreach ($model->getValidators() as $validator) {
// only run validators that applies to the current (swScenario) scenario
if (isset($validator->on[$swScenario])) {
$validator->validate($model);
}
}
// restore original scenario so validation can continue.
$model->setScenario($saveScenario);
}
}
}
}
示例2: validateAttribute
/**
* Validate status change and applies all validators defined by the model for the current transition scenario if
* enableSwValidation is TRUE. If validator parameter 'match' is true, the transition scenario is matched
* against validator scenario (which are assumed to be regular expressions).
*
* @see validators/CValidator::validateAttribute()
* @param CModel $model the model to validate
* @param string $attribute the model attribute to validate
*/
protected function validateAttribute($model, $attribute)
{
Yii::trace(__CLASS__ . '.' . __FUNCTION__, SWActiveRecordBehavior::SW_LOG_CATEGORY);
$value = $model->{$attribute};
if ($model->swValidate($attribute, $value) == true and $this->enableSwValidation === true) {
$swScenario = $this->_getSWScenarioName($model, $value);
Yii::trace('swScenario : ' . $swScenario, SWActiveRecordBehavior::SW_LOG_CATEGORY);
if (!empty($swScenario)) {
if ($this->match === true) {
// validator scenario are Regular Expression that must match the transition scenarion
// for the validator to be executed.
$validators = $model->getValidatorList();
foreach ($validators as $validator) {
//Yii::trace(CVarDumper::dumpAsString($validator));
if ($this->_validatorMatches($validator, $swScenario)) {
Yii::trace('applying validator : ' . CVarDumper::dumpAsString($validator), SWActiveRecordBehavior::SW_LOG_CATEGORY);
$validator->validate($model);
}
}
} else {
$swScenario = SWValidator::SW_SCENARIO_PREFIX . $swScenario;
// execute only validator defined for the current transition scenario ($swScenario)
// getValidators returns validators with no scenario, and the ones
// that apply to the current scenario (swScenario).
$saveScenario = $model->getScenario();
$model->setScenario($swScenario);
$validators = $model->getValidators();
foreach ($model->getValidators() as $validator) {
// only run validators that applies to the current (swScenario) scenario
//Yii::trace(CVarDumper::dumpAsString($validator));
if (isset($validator->on[$swScenario])) {
Yii::trace('applying validator : ' . CVarDumper::dumpAsString($validator), SWActiveRecordBehavior::SW_LOG_CATEGORY);
$validator->validate($model);
}
}
// restore original scenario so validation can continue.
$model->setScenario($saveScenario);
}
}
}
}