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


PHP CModel::swValidate方法代码示例

本文整理汇总了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);
             }
         }
     }
 }
开发者ID:honglei619,项目名称:simpleWorkflow,代码行数:44,代码来源:SWValidator.php

示例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);
             }
         }
     }
 }
开发者ID:niranjan2m,项目名称:Voyanga,代码行数:50,代码来源:SWValidator.php


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