在一个页面与codeigniter会话库之间丢失会话变量 [英] Losing a session variable between one page with codeigniter session library

查看:131
本文介绍了在一个页面与codeigniter会话库之间丢失会话变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中,我试图在两个页面之间存储一个变量,但我得到一个字符串返回images或0 ...或没有什么 - 试图投射它。回声在一个页面上工作,并显示正确的数字,但只要你点击查看到下一页 - 其失去我试图打开在数据库中的cs_sessions,没有什么区别

In my code i am trying to store a variable between two pages but i either get a string return "images" or 0... or nothing- tried casting it.. echoing in on one page works and displays correct number but as soon as you click through the view to the next page- its lost- i tried turning on cs_sessions in the db and made no difference

<?php   
 public function carconfirm($car_id = '')
        {

            if(empty($car_id))
            {
                redirect('welcome');
            }

            $this->load->model('mcars');
            $car = $this->mcars->getCar($car_id);

            $data['car'] = $car->row_array();


            $car_id = (int) $car_id;
            $this->session->set_userdata('flappy', $car_id);
            echo $car_id;



            //insert details 
            //display details

            $this->load->view('phps/carconfirm',$data);
        }

        function confirm()
        {

            //get vars

            $time_slot = $this->session->userdata('slot');
            $person_id = $this->session->userdata('person_id');
            $car_id = $this->session->userdata('flappy');

            $insert_array = array(  'slot'=> $time_slot ,
                                    'car'=> $car_id,
                                    'person_id'=> $person_id
                                );
            print_r($insert_array);

            $this->load->model('mbooking');
            $result = $this->mbooking->addbooking($insert_array);

            if($result)
            {
                redirect('welcome/options');
            }

        }
?>

我丢失的变量是flappy-我改变了名称,看看是否是问题

the variable I'm losing is flappy- i changed the name to see if that was the problem

推荐答案

最后,我修复了这个问题。在SO中也使用此答案: codeigniter设置会话变量和变量不工作,我扫描我的js / css缺少资源。事实证明,我的thickbox.js引用了loadingAnimation.gif,是的,图像文件夹。这是图片来的地方。修复缺少的文件,sesion variabel工作很好。

Finally, I fixed this. Using this answer in SO too : codeigniter setting session variable with a variable not working, I scan my js/css for missing resources. Turn out that, my thickbox.js refer to loadingAnimation.gif in, yes, images folder. That's where the images come. Having fix the missing file, the sesion variabel working just fine.

不确定,为什么CI替换(也许)最后一次添加会话variabel使用这个,但也许是因为CI不使用$ _SESSION全局变量标签。 CMIIW。我使用这篇文章作为提示: http://outraider.com/frameworks/why-your-session-variables-fail-in-codeigniter-how-to-fix-them/

Not sure, why CI replace (maybe) last added session variabel using this, but maybe it's because CI is not using $_SESSION global variabel. CMIIW. I use this article as a hint : http://outraider.com/frameworks/why-your-session-variables-fail-in-codeigniter-how-to-fix-them/

这篇关于在一个页面与codeigniter会话库之间丢失会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆