Cakephp 3 dynamic validation error messages

╄→尐↘猪︶ㄣ 提交于 2019-12-11 04:18:33

问题


I'm validating file uploads in my form and i want to know if it's possible to display a dynamic message using information from the form.

This is my validation model:

public function validationDefault(\Cake\Validation\Validator $validator) {

    $validator
      ->allowEmpty('file')
      ->add('file', array(
        'extension'=>array(
          'rule' => ['extension', ['jpeg', 'png', 'jpg']],
          'message' => '[[fileName]] has no valid extension.'          
        ),
        'fileSize' => array(
          'rule' => array('fileSize', '<=', '100K'),
          'message' => '[[fileName]] exceed 100K.'),
        )
      ));

    return $validator;
}

I would like to replace the message to show for example: 'document.docx has no valid extension.'

I've read that this can be done with a custom validation, but i'm using proper cakephp validation not custom.

is there a way to do it or it can only be donde with a custom validation??

来源:https://stackoverflow.com/questions/41600948/cakephp-3-dynamic-validation-error-messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!