php – CodeIgniter配置文件中的自定义验证错误消息

前端之家收集整理的这篇文章主要介绍了php – CodeIgniter配置文件中的自定义验证错误消息前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是CodeIgniter(v 3.0.0)的新手(来自Cake PHP),我正在尝试将自定义验证错误消息设置为我的一个表单.我正在使用配置文件存储我的所有验证规则,如 here所述.这是我的application / config / form_validation.PHP文件
<?PHP  if (!defined('BASEPATH')) exit('No direct script access allowed');

$config = array(
    'appointments/signup' => array(
        array(
            'field' => 'admin[name]','label' => 'Name','rules' => 'required','errors' => array(
                'required' => 'Please tell us your %s',),array(
            'field' => 'admin[email]','label' => 'Email','rules' => 'required|valid_email|is_unique[users.email]','errors' => array(
                'required' => 'Please enter your %s address','valid_email' => 'Please enter a valid email address','is_unique' => 'That email is already taken. Forgot your password?'
            )
        ),array(
            'field' => 'admin[username]','label' => 'Username','rules' => 'required|min_length[4]|max_length[25]|is_unique[user_settings.username]','errors' => array(
                'required' => 'Please choose a %s','min_length' => '%s must me at least 4 characters long','max_length' => '%s cannot exceen 25 characters','is_unique' => '%s is already taken :('
            )
        ),array(
            'field' => 'admin[phone_number]','label' => 'Phone number','rules' => 'min_length[0]',array(
            'field' => 'admin[password]','label' => 'Password','rules' => 'required|min_length[8]','min_length' => '%s must be at least 8 characters long'
            )
        ),array(
            'field' => 'admin[passconf]','rules' => 'required|matches[admin[password]]','errors' => array(
                'required' => 'Please re-type your %s','matches' => '%ss do not match'
            )
        ),array(
            'field' => 'company[company_name]','label' => 'Organization\'s Name',)
        ),);

正如您所看到的,我正在尝试使用errors数组设置自定义验证反馈,详见here.但我仍然看到全局默认值<字段名称>字段是必需的.信息.

有没有办法在配置文件中设置自定义验证消息,而无需编辑全局默认文件

尝试更改数组中键的顺序,如下所示:
'appointments/signup' => array(
    array(
        'field' => 'admin[name]','errors' => array(
            'required' => 'Please tell us your %s',)

完全相同的问题发生在我身上,经过对核心类的一些调试后,我感觉很愚蠢到尝试这个.

看起来像一个错误,但我没有再进一步.

我使用的是3.0.1版本.

UPDATE

我错了,如果这发生在3.0.0版本上,则不会发生在3.0.1上.我上面描述的是我在数组中用括号做错了.

一切都在按预期工作.

猜你在找的PHP相关文章