lundi 1 avril 2019

CodeIgniter showing different menu using If statement

I have an error in the variable when I try to get the value it says it was undefined While I have already stored the session of the variable "$level" and sent it to the view but the condition of the variable become undefined, is there anything wrong with the code?

The variable that I get is from the login. Also I have tried to call the $level and it work

I have tried to use foreach and non foreach method still none of these are working

View.php

<p>Number 1</p>
<?php if($level->level == '2') ?>
<p>Number 2</p>

admin.php

function index(){       
$level = $this->session->userdata('level');
$this->load->view('view',$level);
}

Login.php

public function do_login()
    {
        $u = $this->input->post("user");
        $p = md5($this->input->post("pass"));

        $cari = $this->model_pesawat->cek_login($u, $p)->row();
        $hitung = $this->model_pesawat->cek_login($u, $p)->num_rows();

        if ($hitung > 0) {

        $data = array('admin_id' => $cari->no_user ,
                            'admin_user' => $cari->username, 
                            'admin_nama' => $cari->nama,
                            'level' => $cari->level,
                            'admin_valid' => TRUE
            );

            $this->session->set_userdata($data);
            redirect('admin','refresh');
        }else{
            echo "maaf username atau password salah";
        }   
    }

I want the result the if statement will show different value in the view depending on the $level of the user

Aucun commentaire:

Enregistrer un commentaire