Losing a session variable between one page with co

2019-01-28 15:59发布

问题:

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

回答1:

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/