使用 codeigniter 会话库在一页之间丢失会话变量

发布于 2024-12-11 18:27:57 字数 1541 浏览 0 评论 0原文

在我的代码中,我试图在两个页面之间存储一个变量,但我要么得到一个字符串返回“images”或0...或者什么都没有-尝试转换它..在一页上回显可以工作并显示正确的数字,但一旦您单击视图进入下一页-它丢失了-我尝试在数据库中打开cs_sessions,但没有什么区别

<?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-我更改了名称以查看这是否是问题所在

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');
            }

        }
?>

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北座城市 2024-12-18 18:27:57

最后,我解决了这个问题。在SO中也使用这个答案:codeigniter使用变量设置会话变量不工作,我扫描我的 js/css 是否缺少资源。事实证明,我的thickbox.js 引用了images 文件夹中的loadingAnimation.gif。这就是图像的来源。修复丢失的文件后,会话变量工作正常。

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

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.

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文