Cakephp 1.3 到 2.0 的转换

发布于 2024-12-11 00:54:08 字数 752 浏览 5 评论 0原文

我正在尝试将 Cake 1.3 应用程序更新到 2.0。在某些模型方法中,我加载会话和电子邮件组件,如下所示:

App::uses('SessionComponent', 'Controller/Component');
App::uses('EmailComponent', 'Controller/Component');

$Session = new SessionComponent();
$Email = new EmailComponent();

但是,当我加载这些页面时,我收到此错误:

Warning (4096): Argument 1 passed to Component::__construct() must be an instance of ComponentCollection, none given, called in /Users/username/Sites/cake2app/app/Model/User.php on line 183 and defined [CORE/Cake/Controller/Component.php, line 77]

Notice (8): Undefined variable: collection [CORE/Cake/Controller/Component.php, line 78]

What's theproper way to load and use Components in Cake 2.0 like we can with Cake 1.3?

I'm trying to update my Cake 1.3 app to 2.0. In some of the Model methods I'm loading the Session and Email components like this:

App::uses('SessionComponent', 'Controller/Component');
App::uses('EmailComponent', 'Controller/Component');

$Session = new SessionComponent();
$Email = new EmailComponent();

However when I load those pages I get this error:

Warning (4096): Argument 1 passed to Component::__construct() must be an instance of ComponentCollection, none given, called in /Users/username/Sites/cake2app/app/Model/User.php on line 183 and defined [CORE/Cake/Controller/Component.php, line 77]

Notice (8): Undefined variable: collection [CORE/Cake/Controller/Component.php, line 78]

What's the proper way to load and use Components in Cake 2.0 like we could with Cake 1.3?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

菩提树下叶撕阳。 2024-12-18 00:54:09

EmailComponent 已被 CakeEmail 类取代,请参阅 http://book.cakephp.org/2.0/en/core-utility-libraries/email.html 了解有关如何使用此类的更多信息。

当您想要访问模型中的会话时,您必须使用 CakeSession 类,而不是 SessionComponent 。您可以包含此类:

App::uses('CakeSession', 'Model/Datasource');

不需要实例化此类。

The EmailComponent has been replaced by the CakeEmail class, see http://book.cakephp.org/2.0/en/core-utility-libraries/email.html for more information about how this class is used.

And instead of the SessionComponent you have to use the CakeSession class when you want to access the session in your model. You can include this class with:

App::uses('CakeSession', 'Model/Datasource');

It is not necessary to instantiate this class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文