在会话数组HMVC Codeigniter中的数组内签入值

时间:2016-03-22 04:18:43

标签: php arrays codeigniter session

我正在制作这个我希望在我的会话中传递用户数据,我可以在我的代码上看到

控制器

gsettings set org.gnome.desktop.interface scaling-factor 1

模型

public function loginValidate(){

    $this->load->library('form_validation');


    $this->form_validation->set_rules('USERNAME','Username','required|trim|callback_validateCreds');
    $this->form_validation->set_rules('PASSWORD','Password','required|trim');

    if($this->form_validation->run($this) == FALSE){

        $this->index();

    }else{
        $data = array(
            'USERNAME' => $this->input->post('USERNAME'),
            'is_logged_in' => true,
--------->>'user_data' => $this->Login_Model->userinfo()
        );

        $this->session->set_userdata($data);
        $this->dashboard();
    }
}

我想要做的是当我登录以检查我的user_data数组中的值时。例如

public function userinfo(){

    $sql = "SELECT
                tbl_users.ID_NUM,
                tbl_users.USERNAME,
                user_group.GROUP_NAME,
                user_rights.RIGHTS,
                usertypes.USERTYPE,
                department.DEPARTMENT
            FROM tbl_users
                INNER JOIN user_group
                ON tbl_users.GROUP_ID = user_group.GROUP_ID
                INNER JOIN user_rights
                ON user_group.GROUP_ID = user_rights.GROUP_ID
                INNER JOIN usertypes
                ON user_rights.RIGHTS = usertypes.USERCODE
                INNER JOIN department
                ON usertypes.DEP_ID = department.DEP_ID
            WHERE tbl_users.USERNAME = ?
            AND tbl_users.PASSWORD = ? ";

    $data = array(
                    'USERNAME' => $this->input->post('USERNAME'),
                    'PASSWORD' => $this->input->post('PASSWORD')
                );

    $query = $this->db->query($sql, $data);
    return $query;
}   

我不能或至少我不认为我可以分解该数组,因为我的查询输出将是例如。

if (userdata array in my sessions array have the value admin){

show this}

如果某个特定值在该数组中,我将如何能够在sessions数组中检查该数组。例如,如果数组有admin1,我会这样做等等。

1 个答案:

答案 0 :(得分:0)

使用此代码

$sessionarray = $this->session->userdata();

$sessionarray['USERNAME'] ;

或你的病情

if($sessionarray['USERNAME']=='admin')