Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.2k views
in Technique[技术] by (71.8m points)

php - Losing a session variable between one page with codeigniter session library

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...