语法错误,意外' - >' Code Igniter中的(T_OBJECT_OPERATOR)

时间:2016-04-01 10:54:17

标签: php codeigniter validation

您好我是Code Ignitor的新手我想知道为什么我的代码产生了这个错误。

function index(){
    $this->load->library('form-validation');
    $this->form-validation-set_rules('username','Username','trim|required');
    $this->form-validation-set_rules('password','Password','trim|required');
    if ($this->form-validation->run() ==  FALSE) {
        $this->load->view('reg_form_view');//failed input
    } else {
        //redirect('reg_success','refresh');
        echo "success";
    }
}

3 个答案:

答案 0 :(得分:1)

我认为您使用了错误的opps对象调用语法。

function index(){
$this->load->library('form_validation');

  $this->form_validation->set_rules('username','Username','trim|required');
$this->form_validation->set_rules('password','Password','trim|required');

if($this->form_validation->run() ==  FALSE){
    $this->load->view('reg_form_view');//failed input
}else{
    //redirect('reg_success','refresh');
    echo "success";
}

阅读formget form validationCodeigniter Form Validation

答案 1 :(得分:0)

尝试使用以下代码吗?

function index(){
    $this->load->library('form_validation');
    $this->form_validation->set_rules('username','Username','trim|required');
    $this->form_validation->set_rules('password','Password','trim|required');
    if ($this->form_validation->run() ==  FALSE) {
        $this->load->view('reg_form_view');//failed input
    } else {
        //redirect('reg_success','refresh');
        echo "success";
    }
}`

答案 2 :(得分:-1)

function index(){
$this->load->library('form_validation');

$this->form_validation->set_rules('username','Username','trim|required');
$this->form_validation->set_rules('password','Password','trim|required');

if($this->form_validation->run() ==  FALSE){
    $this->load->view('reg_form_view');//failed input
}else{
    //redirect('reg_success','refresh');
    echo "success";
}

}