用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1155|回复: 1
收起左侧

[已解决] 使用form_validation 报错

[复制链接]
发表于 2014-7-27 19:57:19 | 显示全部楼层 |阅读模式
版本 2.2.0
使用form_validation 后 报错 Message: Use of undefined constant required - assumed 'required'


源码如下:
PHP复制代码
[/size][/font][/color]
        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');
                }
        }
 
[color=#000]
复制代码


发表于 2014-7-28 10:05:57 | 显示全部楼层
PHP复制代码
$this->form_validation->set_rules('typeName','分类名称',required);
复制代码
改成
PHP复制代码
$this->form_validation->set_rules('typeName','分类名称', 'required');
复制代码


写代码要仔细。

本版积分规则