Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php CodeIgniter 3:未定义的方法CI_Form_验证::setrules()_Php_Codeigniter 3 - Fatal编程技术网

Php CodeIgniter 3:未定义的方法CI_Form_验证::setrules()

Php CodeIgniter 3:未定义的方法CI_Form_验证::setrules(),php,codeigniter-3,Php,Codeigniter 3,我正在尝试使用CodeIgniter 3创建一个简单的登录过程。但是,每次单击登录表单上的“提交”时,我都会遇到此错误: 遇到PHP错误 严重性:错误 消息:调用未定义的方法CI_Form_validation::setrules() 文件名:controllers/Login.php 电话号码:33 回溯: 这是我的控制器代码: class Login extends CI_Controller { public function __construct() { parent:

我正在尝试使用CodeIgniter 3创建一个简单的登录过程。但是,每次单击登录表单上的“提交”时,我都会遇到此错误:

遇到PHP错误

严重性:错误

消息:调用未定义的方法CI_Form_validation::setrules()

文件名:controllers/Login.php

电话号码:33

回溯:

这是我的控制器代码:

class Login extends CI_Controller
{
    public function __construct()
{
    parent::__construct();
    $this->load->helper('form');
    $this->load->library('form_validation');
    $this->load->library('session');
    $this->load->model('login_model');

}

public function index()
{
    if(isset($this->session->userdata['logged_in']))
    {
        $this->load->view('template');
    }else{
        $this->load->view('login');
    }
}

public function auth_user()
{
    $this->form_validation->setrules('username', 'Username', 'trim|required|xss_clean');
    $this->form_validation->setrules('pass', 'Password', 'trim|required|xss_clean');

    if($this->form_validation->run() == TRUE)
    {
        echo 'IT WORKS';
        $data = array(
          'username' => $this->input->post('username'),
          'password' => $this->input->post('pass')
        );
        //check user credentials
        $result = $this->login_model->login($data);

        if($result == TRUE)
        {   //get user info
            $session_data = array(
                'username' => $result[0]->username
            );
            $user_id = $result->staffID;
            $this->login_model->staff_logs($user_id);
            $this->session->set_userdata('logged',$session_data);
            $this->load->view('template');
        }
    }else{
        echo 'IT not work';
    }
}
}
我正在使用PHPStorm,当我将鼠标悬停在form\u validation上时,它表示在类登录中找不到“form\u validation”字段


非常感谢您的回复。谢谢

您缺少set_规则(…)中的

将代码更改为

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

    $this->form_validation->setrules('username', 'Username', 'trim|required|xss_clean');
    $this->form_validation->setrules('pass', 'Password', 'trim|required|xss_clean');