Cakephp 1.3 到 2.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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
EmailComponent
已被CakeEmail
类取代,请参阅 http://book.cakephp.org/2.0/en/core-utility-libraries/email.html 了解有关如何使用此类的更多信息。当您想要访问模型中的会话时,您必须使用
CakeSession
类,而不是SessionComponent
。您可以包含此类:不需要实例化此类。
The
EmailComponent
has been replaced by theCakeEmail
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 theCakeSession
class when you want to access the session in your model. You can include this class with:It is not necessary to instantiate this class.