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


PHP ModelBehavior::beforeValidate方法代码示例

本文整理汇总了PHP中ModelBehavior::beforeValidate方法的典型用法代码示例。如果您正苦于以下问题:PHP ModelBehavior::beforeValidate方法的具体用法?PHP ModelBehavior::beforeValidate怎么用?PHP ModelBehavior::beforeValidate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ModelBehavior的用法示例。


在下文中一共展示了ModelBehavior::beforeValidate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: beforeValidate

 public function beforeValidate(Model $model, $options = array())
 {
     if (array_key_exists($model->alias, $model->request->data)) {
         if (array_key_exists('contact_type_id', $model->data[$model->alias])) {
             $model->validator()->remove('value');
             switch ($model->data[$model->alias]['contact_type_id']) {
                 // 1 -> Mobile, 2 -> Phone, 3 -> Fax, 4 -> Email, 5 -> Other
                 case '1':
                 case '2':
                 case '3':
                     $model->validator()->add('value', 'required', array('rule' => 'Numeric', 'message' => $model->getErrorMessage('valuePhone')));
                     break;
                 case '4':
                     $model->validator()->add('value', 'required', array('rule' => array('email', true), 'message' => $model->getErrorMessage('valueEmail')));
                     break;
                 default:
                     // 5 -> Other
                     $model->validator()->add('value', 'required', array('rule' => 'notEmpty', 'message' => $model->getErrorMessage('value')));
                     break;
             }
         }
     }
     $model->validator()->remove('name');
     $model->validator()->add('name', 'required', array('rule' => 'notEmpty', 'message' => $model->getErrorMessage('value')));
     $model->validator()->remove('contact_type_id');
     $model->validator()->add('contact_type_id', 'required', array('rule' => 'notEmpty', 'message' => $model->getErrorMessage('contact_type_id')));
     return parent::beforeValidate($model, $options);
 }
开发者ID:ivanbautsita,项目名称:gestion-escolar-campus-virtuales,代码行数:28,代码来源:ContactBehavior.php

示例2: beforeValidate

 /**
  * beforeValidate is called before a model is validated, you can use this callback to
  * add behavior validation rules into a models validate array. Returning false
  * will allow you to make the validation fail.
  *
  * @param Model $model Model using this behavior
  * @param array $options Options passed from Model::save().
  * @return mixed False or null will abort the operation. Any other result will continue.
  * @see Model::save()
  */
 public function beforeValidate(Model $model, $options = array())
 {
     //ページデータをセット
     $referencePageId = $model->getReferencePageId($model->data);
     $fields = array('room_id', 'permalink');
     $targetPage = $model->findById($referencePageId, $fields);
     if (empty($targetPage)) {
         return false;
     }
     $model->data['Page']['room_id'] = Current::read('Room.id');
     $slug = $model->data['Page']['slug'];
     if (!isset($slug)) {
         $slug = '';
     }
     $model->data['Page']['slug'] = $slug;
     $permalink = '';
     if (strlen($targetPage['Page']['permalink']) !== 0) {
         $permalink = $targetPage['Page']['permalink'] . '/';
     }
     $permalink .= $slug;
     $model->data['Page']['permalink'] = $permalink;
     $model->data['Page']['is_published'] = true;
     $model->data['Page']['is_container_fluid'] = false;
     return parent::beforeValidate($model, $options);
 }
开发者ID:Onasusweb,项目名称:Pages,代码行数:35,代码来源:PageBehavior.php

示例3: beforeValidate

 public function beforeValidate(Model $Model, $options = array())
 {
     parent::beforeValidate($Model, $options);
     if ($this->settings[$Model->alias]['before'] === 'validate') {
         return $this->geocode($Model);
     }
     return true;
 }
开发者ID:Jony01,项目名称:LLD,代码行数:8,代码来源:GeocoderBehavior.php

示例4: beforeValidate

 public function beforeValidate(Model $Model)
 {
     parent::beforeValidate($Model);
     if ($this->settings[$Model->alias]['before'] == 'validate') {
         $this->process($Model);
     }
     return true;
 }
开发者ID:robksawyer,项目名称:grabitdown,代码行数:8,代码来源:TypographicBehavior.php

示例5: beforeValidate

 public function beforeValidate(Model $Model)
 {
     $return = parent::beforeValidate($Model);
     if ($this->settings[$Model->alias]['before'] == 'validate') {
         # we dont want to return the value, because other fields might then not be validated
         # (save will not continue with errors, anyway)
         $this->confirm($Model, $return);
     }
     return $return;
 }
开发者ID:robksawyer,项目名称:grabitdown,代码行数:10,代码来源:MasterPasswordBehavior.php

示例6: beforeValidate

 public function beforeValidate(Model $model, $options = array())
 {
     if (!empty($model->data[$model->alias])) {
         $save = array('lista' => $this->listId);
         foreach ($model->data[$model->alias] as $field => $value) {
             if (!empty($this->fields[$field])) {
                 $this->toSave[$this->fields[$field]] = $value;
             }
         }
         $this->toSave = array_merge($save, $this->toSave);
     }
     return parent::beforeValidate($model, $options);
 }
开发者ID:lsantosc,项目名称:cakephp-mediapost,代码行数:13,代码来源:MediaPostBehavior.php

示例7: beforeValidate

	/**
	* Trim através do callback beforeValidate
	*
	* @see ModelBehavior::beforeValidate()
	*/
	public function beforeValidate(Model $model, $options = array())
	{
		parent::beforeValidate($model, $options);

		$this->_Model = $model;

		if (isset($this->_disabledFor[$model->alias])) {
			return true;
		}

		$this->_autoTrim();

		return true;
	}
开发者ID:radig,项目名称:user_guard,代码行数:19,代码来源:AutoTrimBehavior.php

示例8: beforeValidate

 /**
  * beforeValidate is called before a model is validated, you can use this callback to
  * add behavior validation rules into a models validate array. Returning false
  * will allow you to make the validation fail.
  *
  * @param Model $model モデル
  * @param array $options Options passed from Model::save().
  * @return mixed False or null will abort the operation. Any other result will continue.
  * @link http://book.cakephp.org/2.0/ja/models/callback-methods.html#beforevalidate
  * @see Model::save()
  */
 public function beforeValidate(Model $model, $options = array())
 {
     parent::beforeValidate($model, $options);
     if (in_array('edit', $options, true)) {
         // 編集時の動画 任意 対応
         if (isset($model->data[$model->alias][Video::VIDEO_FILE_FIELD]['size']) && $model->data[$model->alias][Video::VIDEO_FILE_FIELD]['size'] === 0) {
             unset($model->data[$model->alias][Video::VIDEO_FILE_FIELD]);
         }
         // 編集時のサムネイル 任意 対応
         if (isset($model->data[$model->alias][Video::THUMBNAIL_FIELD]['size']) && $model->data[$model->alias][Video::THUMBNAIL_FIELD]['size'] === 0) {
             unset($model->data[$model->alias][Video::THUMBNAIL_FIELD]);
         }
     }
     return true;
 }
开发者ID:s-nakajima,项目名称:videos,代码行数:26,代码来源:VideoValidationBehavior.php

示例9: beforeValidate

 /**
  * Eseguita prima di una save(). Controlla se i campi specificati nelle impostazioni
  * sono vuoti e in tal caso li inizializza con il rispettivo valore.
  *
  * @param Model $Model Model che usa il behavior
  * @param array $options
  * @return array
  */
 public function beforeValidate(Model $Model, $options = array())
 {
     // Scorro i model presenti
     foreach ($Model->data as $m => $data) {
         // Controllo se vi sono campi per questo model
         if (isset($this->settings['fields'][$m])) {
             // Scorro i fields per questo model nei settings
             foreach ($this->settings['fields'][$m] as $field => $value) {
                 // Controllo se il campo esiste nel data ed è vuoto
                 if (array_key_exists($field, $data) && (!$data[$field] || is_null($data[$field]))) {
                     debug('modifico campo: ' . $data[$field]);
                     $Model->data[$m][$field] = $value;
                 }
             }
         }
     }
     return parent::beforeValidate($Model, $options);
 }
开发者ID:eliagentili,项目名称:entheos_web_utilities,代码行数:26,代码来源:DefaultableBehavior.php

示例10: beforeValidate

 public function beforeValidate(Model $Model, &$queryData)
 {
     parent::beforeValidate($Model);
     if (!empty($this->Model->whitelist)) {
         $this->Model->whitelist = array_merge($Model->whitelist, $this->fields());
     }
     if (!$this->_validateCaptchaMinTime($Model->data[$Model->alias])) {
         $this->Model->invalidate('captcha', 'captchaResultTooFast', true);
     } elseif (!$this->_validateCaptchaMaxTime($Model->data[$Model->alias])) {
         $this->Model->invalidate('captcha', 'captchaResultTooLate', true);
     } elseif (!$this->_validateDummyField($Model->data[$Model->alias])) {
         $this->Model->invalidate('captcha', 'captchaIllegalContent', true);
     } elseif (in_array($this->settings[$Model->alias]['type'], array('active', 'both')) && !$this->_validateCaptcha($Model->data[$Model->alias])) {
         $this->Model->invalidate('captcha', 'captchaResultIncorrect', true);
     }
     unset($Model->data[$Model->alias]['captcha']);
     unset($Model->data[$Model->alias]['captcha_hash']);
     unset($Model->data[$Model->alias]['captcha_time']);
     return true;
 }
开发者ID:robksawyer,项目名称:tools,代码行数:20,代码来源:captcha.php

示例11: beforeValidate

 public function beforeValidate(Model $model, $options = array())
 {
     $fields = $this->settings[$model->alias];
     $alias = $model->alias;
     $fieldName = $fields['content'];
     if (!empty($model->data[$alias][$fieldName])) {
         $file = $model->data[$alias][$fieldName];
         if ($file['error'] == 4 && $fields['allowEmpty'] == true) {
             unset($model->data[$alias][$fieldName]);
         }
     } else {
         // if the file is null, remove validation
         if (!empty($model->data[$model->alias][$fields['name']])) {
             unset($model->validate[$fieldName]);
             $model->data[$alias][$fields['name']] = null;
             $model->data[$alias][$fieldName] = null;
             return true;
         }
     }
     return parent::beforeValidate($model, $options);
 }
开发者ID:ivanbautsita,项目名称:gestion-escolar-campus-virtuales,代码行数:21,代码来源:FileUploadBehavior.php

示例12: beforeValidate

 /**
  * Validação é feita no callback beforeValidate()
  *
  * @see Cake/Model/ModelBehavior::beforeValidate()
  *
  * @return bool $success
  */
 public function beforeValidate(Model $model, $options = array())
 {
     parent::beforeValidate($model, $options);
     $this->model = $model;
     if (!empty($this->settings['preConditions']) && is_array($this->settings['preConditions'])) {
         if (!$this->evalConditions($this->settings['preConditions'])) {
             return true;
         }
     }
     $pass = null;
     if (isset($model->data[$model->alias][$this->settings['fields']['password']])) {
         $pass = $model->data[$model->alias][$this->settings['fields']['password']];
     }
     $confirm = null;
     // caso haja um campo referente a confirmação de senha
     if ($this->settings['haveConfirm'] && isset($model->data[$model->alias][$this->settings['fields']['confirm']])) {
         $confirm = $model->data[$model->alias][$this->settings['fields']['confirm']];
     }
     $success = $this->isValidPassword($pass, $confirm);
     if ($success === true) {
         return true;
     }
     // adiciona os erros encontrados no atributo validationErrors do modelo atual
     $model->validationErrors = array_merge($model->validationErrors, $success);
     // caso a configuração force a limpeza dos valores (senha e confirmação)
     if (!$this->settings['unsetInFailure']) {
         return true;
     }
     if (isset($model->data[$model->alias][$this->settings['fields']['password']])) {
         unset($model->data[$model->alias][$this->settings['fields']['password']]);
     }
     if (isset($model->data[$model->alias][$this->settings['fields']['confirm']])) {
         unset($model->data[$model->alias][$this->settings['fields']['confirm']]);
     }
     return true;
 }
开发者ID:radig,项目名称:pass_validator,代码行数:43,代码来源:PassValidatorBehavior.php

示例13: beforeValidate

 function beforeValidate(&$Model)
 {
     extract($this->settings);
     foreach ($Model->hasAndBelongsToMany as $assoc_key => $assoc_model) {
         if (empty($Model->data[$assoc_key][$form_field])) {
             continue;
         }
         $tagIds = array();
         if ($assoc_model['className'] == $assoc_classname) {
             if (!empty($Model->data[$assoc_key])) {
                 $tagIds = $this->_getTags($Model, $assoc_key, $assoc_model);
             }
             if (!empty($tagIds)) {
                 foreach ($tagIds as $key => &$value) {
                     $value[$assoc_model['with']][$assoc_model['associationForeignKey']] = $value[$assoc_key]['id'];
                     $Model->data[$assoc_key][$key] = $value;
                 }
                 unset($value);
                 unset($Model->data[$assoc_key][$form_field]);
             }
         }
     }
     return parent::beforeValidate($Model);
 }
开发者ID:voidet,项目名称:tag_time,代码行数:24,代码来源:tag_time.php

示例14: beforeValidate

 public function beforeValidate(\Model $model, $options = array())
 {
     return parent::beforeValidate($model, $options);
 }
开发者ID:jgprolluxer,项目名称:prosales,代码行数:4,代码来源:AppmenuBehavior.php

示例15: beforeValidate

 /**
  * Run before a model is saved, used to set up slug for model.
  *
  * @param object $model Model about to be saved.
  * @return boolean true if save should proceed, false otherwise
  */
 function beforeValidate($model)
 {
     $return = parent::beforeValidate($model);
     $settings = $this->settings[$model->alias];
     $fields = (array) $settings['label'];
     if ($settings['real']) {
         foreach ($fields as $field) {
             if (!$model->hasField($field)) {
                 return $return;
             }
         }
     }
     if ((!$settings['real'] || $model->hasField($settings['slug'])) && ($settings['overwrite'] || empty($model->id))) {
         $label = '';
         foreach ($fields as $field) {
             if (!empty($model->data[$model->alias][$field])) {
                 $label .= (!empty($label) ? ' ' : '') . $model->data[$model->alias][$field];
             }
         }
         if (!empty($label)) {
             $slug = $this->_slug($label, $settings);
             $conditions = array("{$model->alias}.{$settings['slug']} LIKE" => "{$slug}%");
             if (!empty($model->id)) {
                 $conditions["{$model->alias}.{$model->primaryKey} <>"] = $model->id;
             }
             $result = $model->find('all', array('conditions' => $conditions, 'fields' => array($model->primaryKey, $settings['slug']), 'recursive' => -1));
             $sameUrls = null;
             if (!empty($result)) {
                 $sameUrls = Set::extract($result, '/' . $model->alias . '/' . $settings['slug']);
             }
             // If we have collissions
             if (!empty($sameUrls)) {
                 if (!in_array($slug, $sameUrls)) {
                     $slug = $slug;
                 } else {
                     sort($sameUrls);
                     if ($sameUrls[0] == $slug and count($sameUrls) == 1) {
                         $slug = "{$slug}{$settings['separator']}1";
                     } else {
                         $suffix = 1;
                         $slugLength = strlen($slug) + 1;
                         foreach ($sameUrls as $aSlug) {
                             $currentSuffix = substr($aSlug, $slugLength);
                             if ($suffix == $currentSuffix) {
                                 $suffix++;
                             }
                         }
                         $slug = "{$slug}{$settings['separator']}{$suffix}";
                     }
                 }
             }
             $model->data[$model->alias][$settings['slug']] = $slug;
             $this->_addToWhitelist($model, $settings['slug']);
         }
     }
     return $return;
 }
开发者ID:josegonzalez,项目名称:cakephp-app-skellington,代码行数:63,代码来源:sluggable.php


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