cakephp 3.x how to use session in model?

1.3k Views Asked by At

We are developing shopping cart application. Our application we are merging the cart items with login user when user logged in. So can you please help me how to use Session inside the model

1

There are 1 best solutions below

0
On

One workaround is using Network Session object

// In Table class include this line at the top
use Cake\Network\Session;

public function getSession(){
   $session = new Session();
   debug($session->read()); die;
} 

I don't know whether it's optimal solution or not. Other way of doing is discussed here Session accessibility in model and behavior