cakephp 3.x如何在模型中使用会话?

cakephp 3.x如何在模型中使用会话?,cakephp,cakephp-3.1,Cakephp,Cakephp 3.1,我们正在开发购物车应用程序。我们的应用程序在用户登录时将购物车项目与登录用户合并。因此,您可以帮助我如何在模型中使用会话吗?一种解决方法是使用网络会话对象 // In Table class include this line at the top use Cake\Network\Session; public function getSession(){ $session = new Session(); debug($session->read()); die; }

我们正在开发购物车应用程序。我们的应用程序在用户登录时将购物车项目与登录用户合并。因此,您可以帮助我如何在模型中使用会话吗?

一种解决方法是使用网络会话对象

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

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

我不知道这是否是最佳解决方案。此处讨论了其他方法

一种解决方法是使用网络会话对象

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

public function getSession(){
   $session = new Session();
   debug($session->read()); die;
} 
我不知道这是否是最佳解决方案。这里讨论了其他方法