PHP MVC - 使用与同名控制器不直接相关的模型是不好的做法吗?
我目前正在开发一个基于 MVC 的 PHP 项目。我的脚本基本上会向客户发送一些电子邮件,并且需要从数据库中提取电子邮件模板。我有一个邮件帮助程序库,它提供了 SWIFT Mailer 类的接口。对于数据相关的东西(例如从数据库中提取电子邮件模板),即使没有邮件控制器,使用新模型(让我们称之为“mail_model.php”)是不是不好的做法?
结构快速概览:
控制器 - 客户(一些电子邮件发送到这里) - 发票(更多电子邮件会发送至此处)
型号 - 客户 - 发票 - 邮件
浏览 - 客户 - 发票
助手/图书馆 - 客户 - 发票 - 邮件(SWIFT 接口)
(注意:这只是一个简化的示例)
所以是的,我真的只是想看看这是否是一个禁止出价的交易,或者是否可以这样做。如果不是,有人有其他方法吗?
感谢您抽出时间!
I'm currently working on an MVC based PHP project. My script basically will be sending out some emails to clients, and it needs to pull an email template from the database. I've got a mail helper library which provides an interface into the SWIFT Mailer class. For the data related stuff (e.g pulling the email template from the DB) is it bad practice to use a new model (lets call it 'mail_model.php') even though there wont be a mail controller?
A quick overview of the structure:
CONTROLLERS
- Client (some emails get sent here)
- Invoices (some more emails get sent here)
MODELS
- Client
- Invoices
- Mail
VIEWS
- Client
- Invoices
HELPERS/LIBRARIES
- Clients
- Invoices
- Mail (interface for SWIFT)
(nb: this is just a dumbed down example)
So yeah, I really just wanted to see if this was a bid no-no or if its ok to be doing this. If its not, does anyone have an alternate way of doing it?
Thanks for your time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,从控制器到模型没有固定的相关性。
模型抽象持久存储(即数据库)操作,控制器处理请求。
控制器可以针对某些请求使用多个模型,而针对另一个请求则不使用多个模型。
Actually there's no fix correlation from controllers to models.
Models abstract persistent strage (i.e. database) operations, and controllers handle requests.
A controller may use several models for some request and none for another.
我个人并不认为拥有一个可由多个控制器使用的模型有什么问题。但不确定这是否是你的问题,因为这有点令人困惑。
I don't personally see a problem with having a model that could be used by multiple controllers. But not sure if thats your question, as it's a bit confusing.