Ant*_*tin 1 php cakephp cakephp-4.x
如何访问 cakephp 4.0 组件中的请求对象和会话数据?
我在组件中的以下代码中升级后
出现以下错误Call to a member function getSession() on null 。$session = $this->request->getSession();
要从组件内部访问控制器,应该使用$this->getController()(https://book.cakephp.org/4/en/controllers/components.html#accessing-a-component-s-controller)。
要访问会话,您可以使用$session=$this->getController()->getRequest()->getSession().
| 归档时间: |
|
| 查看次数: |
625 次 |
| 最近记录: |