【问题标题】:Validate message cakephp error?验证消息 cakephp 错误?
【发布时间】:2017-03-22 23:48:30
【问题描述】:

我怎样才能像这样在 cakephp 中自定义消息验证???

$value=$this->data['value'];
'count_device' => array(
                    'rule' => 'checkvalues',
                    'message' =>'Value must be greater than or equal to'.$value;
                   ));

消息是错误如何解决????

【问题讨论】:

    标签: validation message


    【解决方案1】:

    像这样尝试,

    $value=$this->data['value'];
    'count_device' => array(
                        'rule' => 'checkvalues',
                        'message' =>'Value must be greater than or equal to'.$value;
                       ));
    
    public function checkvalues($value,$context){
            if($context['data']['count_device'] > $value) {
                return false;
            } else {
                return true;
            }
        }
    

    【讨论】:

    • 我的意思是,我想显示消息前:“值必须大于或等于 8”,其中 8 是 $value。我尝试'值必须大于或等于'.$value;这个错误:'(
    • if(!empty($error_msg)){ $this->Flash->error( __("请修复以下错误:".implode("\n \r", $error_msg)) ); }
    • 您可以在控制器中查看消息
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多