-
-
Save k1LoW/153897 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AppModel extends Model { | |
var $withFieldName = false; | |
var $error_messages = array(); | |
function _setErrorMessageI18n() { | |
$this->error_messages['empty'] = __('Error Hoge',true); | |
} | |
function beforeValidate(){ | |
$this->_setErrorMessageI18n(); | |
foreach( $this->validate as $fieldname => $ruleSet ){ | |
foreach( $ruleSet as $rule => $rule_info ){ | |
if(!empty($this->validate[$fieldname][$rule]['rule'])) { | |
$rule_option = $this->validate[$fieldname][$rule]['rule']; | |
if( $error_message = $this->_getErrorMessageI18n( $rule ) ) { | |
$this->validate[$fieldname][$rule]['message'] = vsprintf($error_message, $rule_option); | |
}elseif( !empty($this->validate[$fieldname][$rule]['message']) ){ | |
$this->validate[$fieldname][$rule]['message'] = __( $this->validate[$fieldname][$rule]['message'], true); | |
} | |
if( $this->withFieldName && !empty($this->validate[$fieldname][$rule]['message']) ){ | |
$this->validate[$fieldname][$rule]['message'] = __( $fieldname ,true) . ' : ' . $this->validate[$fieldname][$rule]['message']; | |
} | |
} | |
} | |
return true; | |
} | |
function _getErrorMessageI18n( $rule ){ | |
if( array_key_exists($rule, $this->error_messages) ){ | |
return $this->error_messages[$rule]; | |
}else{ | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment