简体   繁体   English

如何在cakephp中“适当地”构造电子邮件系统

[英]How to “properly” architect email system in cakephp

So I recently came to be working on a cake 2.0 codebase that had already been mostly written. 因此,我最近开始研究已经大部分编写的Cake 2.0代码库。

It is setup with a complex and powerful email system in components. 它使用组件中的复杂而强大的电子邮件系统进行设置。 However, there are many valid cases for sending emails from a model, mostly as debugging messages to developers, and there seems to be a rule in cake that models cannot normally access components. 但是,有很多有效的情况可以从模型发送电子邮件,主要是作为调试消息发送给开发人员,并且似乎存在一个规则,即模型通常无法访问组件。

I don't want to write another alternative email function because this isn't dry, and I want the functionality to be shared. 我不想编写另一个电子邮件功能,因为它不干,我希望功能可以共享。 I also cannot instantiate a new component because it is set to inherit from a class that takes a controller in the constructor. 我也无法实例化一个新组件,因为它被设置为从在构造函数中带有控制器的类继承。

I don't understand how this application could be refactored to work properly in theory by cake philosophy. 我不明白如何通过蛋糕哲学将该应用程序重构为在理论上正常工作。

Components? 组件? The previous developers did it wrong. 以前的开发人员做错了。 The correct way would be to use CakeEmail and transport adapters. 正确的方法是使用CakeEmail和传输适配器。 The manual has a page about CakeEmail and how to write transports . 手册中有关于CakeEmail以及如何编写传输的页面

It is not just a rule in Cake but in MVC in general that models should not access components. 模型不仅不应该在Cake中使用,而且在MVC中通常不应访问组件。 By the fact the previous devs didnt pay attention to that I assume there is more wrong with the general architecture of the app. 实际上,以前的开发人员没有注意我认为应用程序的一般体系结构存在更多错误的事实。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM