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