ren2881971 发表于 2014-7-27 19:57:19

使用form_validation 报错

版本 2.2.0
使用form_validation 后 报错 Message: Use of undefined constant required - assumed 'required'


源码如下:

        public function add($page='add'){
                if (! file_exists(APPPATH.'/views/type/'.$page.'.php')) {
                        show_404();
                }
                $this->load->helper('form');
                $this->load->library('form_validation');
                $this->form_validation->set_rules('typeName','分类名称',required);
                if ($this->form_validation->run() === FALSE) {
                        $data['title'] = '添加分类';
                        $this->load->view('templates/header',$data);
                        $this->load->view('type/add.php');
                        $this->load->view('templates/footer');
                }else{
                        $this->type_model->insert_type();
                        $data['title'] = '分类名称列表';
                        $this->load->view('templates/header',$data);
                        $this->load->view('type/list');
                        $this->load->view('templates/footer');
                }
        }



Hex 发表于 2014-7-28 10:05:57

$this->form_validation->set_rules('typeName','分类名称',required); 改成
$this->form_validation->set_rules('typeName','分类名称', 'required');

写代码要仔细。
页: [1]
查看完整版本: 使用form_validation 报错