Passing a variable between two actions using Session Component in CakePHP 2.5.3


#1

I want to pass a variable between two actions using Session component. the variable session read returns a value in the payment action but it returns NULL in the action checkout.

Here is the code:

       //AppController.php
        class AppController extends Controller
        {
            public $components = array('Session', 'Auth', 'Cookie', 'Email');
            // rest of the code    
        }
        //OrderController.php
        class OrdersController extends AppController
        {
            public $components = array('Paginator','Session'); 
            // rest of the code
            public function payment($hash=null)
            {
                //some code
                $priceTND = 123,55; //just for the test  
                $this->Session->write('priceCTP',$priceTND); 
                //var_dump($this->Session->read('priceCTP')); it returns 123.55
                // rest of the code
            }
            public function checkout()
            { 
                $this->render("checkout",FALSE);

                $price = $this->Session->read('priceCTP');
                var_dump($price); // it returns NULL
                // rest of the code
            }
        }

#2

Hi Tarek,

Your app is using CakePHP 2.5.3, which was released on July 2014. As a first approach to the issue, I would update to 2.9.6, last release of CakePHP 2 so far. Or, at least, to 2.5.9, which was the last security update of the 2.5 branch.

Specifically, versions 2.5.4 and 2.5.6 solved some session issues:



#3

Thank you man, you are right. I have to upgrade the code.