CodeIgniter - 自定义配置文件中的验证规则

时间:2011-12-28 13:16:58

标签: php validation codeigniter

在CodeIgniter用户指南上我读过我们可以将验证规则保存到application / config / form_validation.php中的数组

http://codeigniter.com/user_guide/libraries/form_validation.html#savingtoconfig

我想知道是否可以将这些规则保存到不同的配置文件中,例如application / config / my_library.php

Form_validation.php应该是这样的:

<?php $config = array(
             'signup' => array(
                                array(
                                        'field' => 'username',
                                        'label' => 'Username',
                                        'rules' => 'required'
                                     ),
                                array(
                                        'field' => 'password',
                                        'label' => 'Password',
                                        'rules' => 'required'
                                     ),
                                array(
                                        'field' => 'passconf',
                                        'label' => 'PasswordConfirmation',
                                        'rules' => 'required'
                                     ),
                                array(
                                        'field' => 'email',
                                        'label' => 'Email',
                                        'rules' => 'required'
                                     )
                                ),
             'email' => array(
                                array(
                                        'field' => 'emailaddress',
                                        'label' => 'EmailAddress',
                                        'rules' => 'required|valid_email'
                                     ),
                                array(
                                        'field' => 'name',
                                        'label' => 'Name',
                                        'rules' => 'required|alpha'
                                     ),
                                array(
                                        'field' => 'title',
                                        'label' => 'Title',
                                        'rules' => 'required'
                                     ),
                                array(
                                        'field' => 'message',
                                        'label' => 'MessageBody',
                                        'rules' => 'required'
                                     )
                                )                          
           );

其中每个子阵列(如“电子邮件”或“注册”)都标识不同的表单

1 个答案:

答案 0 :(得分:0)

它必须是单个文件,但您可以将规则拆分为集合,如您所引用的链接中所述,&#34;创建规则集&#34;