语法错误,意外'->';代码点火器中的(T_OBJECT_OPERATOR)


syntax error, unexpected '->' (T_OBJECT_OPERATOR) in Code Igniter

嗨,我是新来的To 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";
    }
}

我认为您对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表单验证和Codeigniter表单验证

试试下面的代码,它会起作用`

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";
    }
}`
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";
}
}