尝试将组件添加到 CakePHP 中的 AppController 时出错

Getting an error when trying to add component to AppController in CakePHP

我正在尝试将 SessionComponent 添加到我的控制器,以便能够即时更改我的应用程序的语言。以下代码段(特别是第 3 行)是我根据 http://book.cakephp.org/2.0/en/controllers/components.html#using-components

尝试过的代码
class AppSettingsController extends AppController
{
    var $components = array('Session');

但是当我尝试 运行 我的控制器的任何操作时,我得到:

SessionComponent could not be found.

Create the class SessionComponent below in file:         
src/Controller/Component/SessionComponent.php

就好像 SessionComponent 不存在一样。我能够找到的所有答案都表明我已经完成的工作应该有效。你知道我可能错过了什么或者我应该研究什么来解决它吗?

从您的 post 我得出结论,您参考了 CakePHP 2 文档,但错误消息告诉我们您正在使用 CakePHP 3 !

src/Controller/Component/SessionComponent.php

cakephp 3 具有以下组件:

  • 身份验证
  • Cookie
  • 跨站请求伪造
  • 快闪
  • 安全
  • 分页
  • 请求处理

下面是如何在您的应用程序中使用会话:

http://book.cakephp.org/3.0/en/development/sessions.html#accessing-the-session-object