dongzhijing8202 2019-04-01 12:42
浏览 147

CodeIgniter使用If语句显示不同的菜单

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

<?php if($level->level == '1') ?>
<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

  • 写回答

3条回答 默认 最新

  • dongza6247 2019-04-01 12:45
    关注

    You need to pass array to the CodeIginter view.

    And the array's keys will be used as individual elements in view.

    Its similar to extract() function.

    So, you should pass $data and add $level into it.

    $data['level'] = $level;
    $this->load->view('view', $data);
    

    In your view, you can access $level from Controller as $level.

    No need to care for $data

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP