图像代理应该驻留在 MVC 结构中的什么位置? (PHP)
我正在尝试掌握 MVC 结构并尝试决定我的文件应该放在哪里。
我有一个 php 脚本,它从不可通过网络访问的位置读取图像并将其输出。
它属于控制器还是视图?
同样,加载 smarty 模板(从视图)并设置值并输出它的脚本应该在控制器还是视图中?
感谢您的帮助!
I'm trying to get to grips with the MVC structure and trying to decide where my files should go.
I have a php script which reads an image from a non-web accessible location and outputs it.
Does it belong in the Controller or the View?
Likewise, should a script that loads a smarty template (from the view) and sets values and output it be within the Controller or the View?
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我第二。建模是因为控制器变胖的速度太快了。
它应该是一个模型,因为只有模型才应该知道在哪里可以找到数据以及如何访问它们(在您的情况下是文件系统)。此外,数据转换最好在模型中完成。
敢于即时输出压缩的 JPG 文件而不是 10MB+ BMP 文件吗?如果您的服务器可以管理它,您可以在控制器中调用 $ImageModel->outputAsJPEG() ,一起跳过视图脚本或委托给视图脚本/智能函数。
I Second. Model because controllers get fat so fast.
It should be a model as only Models should be allowed to know where data can be found and how they should be access (filesystem in your case). Also data conversion is best done in a model.
Dare to output compressed JPGs instead 10MB+ BMP-files on the fly? If your server can manage it your $ImageModel->outputAsJPEG() could be called in the controller, skipping viewscripts alltogether or delegated to the viewscripts/smarty functions.
对我来说,你的两个例子听起来都像模型逻辑,但第二个例子有点模糊。模板是一个视图,但设置值可能是模型逻辑(如果它不简单的话)。
您的视图应该调用模型来获取它需要的东西,控制器应该决定显示哪个视图并实例化正确的模型以将其移交给视图。
如果您可以将代理图像脚本视为模型,那么只需在视图中调用它即可。
Both your examples sound like Model logic to me, but the second example is a little more fuzzy. A template is a View but setting values is probably Model logic if it's non-trivial.
Your View should invoke a Model to get stuff it needs, and the Controller should be deciding which View to display and instantiating the right Model to hand off to the View.
If you can treat your proxy image script as a Model then just invoke it in the View.
在这种情况下只有模型。
Only Model in this situation.