doujiyuan0211 2019-01-28 16:37
浏览 36

Codeigniter Session-> userdata(curs)为null

I create the session curs inside the controller function step2. The form action of the view go to this function but the session is null.

Controller step2:

public function step2($id=null){
    $this->load->library('session');
    $this->load->model('model_cursos');

    if(!$this->input->post()){

        if($id == null){
            redirect("Cursos/administrar");
        }

        $this->session->set_userdata('curs',$id);

        var_dump($this->session->userdata('curs'));// is not null

    }else{
        var_dump($this->session->all_userdata()); // is null
        exit;


        /*$titol = $_POST['titol'];
        $data = $_POST['data'];
        $horesT = $_POST['horesT'];
        $horesD = $_POST['horesD']; */

        //var_dump($titol,$data,$horesD,$horesT);

        //$this->model_cursos->afegirDades($id,$titol,$data,$horesT,$horesD);
        //$this->model_cursos->crearSessions($id,$data,$horesT,$horesD);
    }
    $this->load->view('step2');

}

View step2:

    <form id="step2" method="post" action="<?php echo site_url('Cursos/step2'); ?>">

        <label>Titol</label><br>
        <input type="text" name="titol" id="titol"><br><br>
        <label>Data inici</label><br>
        <input type="date" name="data" id="data"><br><br>
        <label>Hores totals</label><br>
        <input type="number" name="horesT" id="horesT"><br><br>
        <label>Hores diaries</label><br>
        <input type="number" name="horesD" id="horesD"><br><br>

        <input type='submit' name='next' value='Afegir dades'/>
    </form>
</div>
  • 写回答

1条回答 默认 最新

  • doulu1907 2019-01-30 15:16
    关注

    On this line :

    var_dump($this->session->all_userdata());
    

    It's normal that your session is empty because you never insert data on it when you passed directly in the 'else' condition.

    If you put this line like this in the 'if' condition :

    var_dump($this->session->all_userdata());
    var_dump($this->session->userdata('curs'));
    

    Do you see something for the userdate('curs') ?

    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计