Calling a Controller function in another Controller in CodeIgniter

后端 未结 4 1229
盖世英雄少女心
盖世英雄少女心 2020-12-06 06:10

I have a controller \"user\" in my codeigniter application. This controller has a function called logged_user_only():

public function logged_use         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-06 06:23

    Function login in Controller Login

    $data =array('username' => $this->input->post('username'), 'password' => $this->input >post('password')) $query = $this->db->get_where('usertable',$data)
        if ($query->num_rows() == 1) {
            $data = array(
                'username' => $this->input->post('username'),
                'logged_in' => TRUE,
                'role' => "user");
            $this->session->set_userdata($data);
            redirect('home');
        } 
    

    Function Construct in Controller user

    if ($this->session->userdata('logged_in') == TRUE && $this->session->userdata('role') == "user") {} else {redirect('home');}
    

提交回复
热议问题