MVC 最佳实践问题:从模型生成 XML 数据提取?
我正在使用 MVC 框架开发一个以 XML 格式生成数据提取的应用程序。使用 cron 每小时生成一个提取文件。
我有一个名为 DataExtract 的模型,用于存储提取的日期范围。我还有一个包含用于生成摘录的 XML 的视图。
它没有控制器,因为它不是前端的一部分。
有人可以建议这里的最佳实践吗?生成提取文件时可以直接从模型解析 XML 视图吗?
I'm using an MVC framework to develop an app that produces data extracts in XML format. An extract file is produced hourly using cron.
I have a model called DataExtract that stores the date range for the extract. I also have a view containing the XML used to generate the extract.
There's no controller for it, since it's not part of the front end.
Can anyone advise on the best practice here? Is it okay to parse the XML view directly from the model when producing the extract file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯...在我看来,“我不希望通过应用程序查看报告”,意味着可以打破 MVC 模式。
Hmm... the way I see it, "I don't want the report to be viewable through the application", means it is ok to break the MVC pattern.
我想我读错了:您每小时都会创建一个 xml 文件,但您不希望通过应用程序读取该文件? htaccess 文件是否应该阻止这种情况(如果该文件存在,则打开该文件而不是应用程序)?
您是否不希望从地址栏访问 cron 文件?
我也在运行一个 cron 作业。和你一样,我也通过 ZF 运行它。
我已将引导程序设置拆分为单独的文件。在我的 index.php 文件中,我包含引导文件,然后调用 $application->run。在我的 cron 文件中,我包含引导程序,但不运行该应用程序。在文件的顶部我有:
这段代码阻止服务器以外的任何东西运行 cron 作业。
我同意@guided1。您没有在屏幕上显示任何内容,MVC 的 V 部分不在窗口中。我的 cron 文件正在处理 C 的部分(调用任何模型)。
I think I'm mis-reading this: you are creating an xml file every hour but you don't want this file to be read through the application? Shouldn't the htaccess file prevent that (if the file exists then open that instead of the application)?
Is it that you don't want the cron file to be accessible from the address bar?
I am running a cron job as well. Like you I am running it through ZF.
I have split my bootstrap setup to a separate file. In my index.php file I include the bootstrap file, then call $application->run. In my cron file I include the bootstrap but don't run the application. At the top of the file I have:
This snippet of code stops anything other than the server from running the cron job.
I agree with @guided1. You are not showing anything to the screen, the V part of MVC is out the window. My cron file is handling the part of the C (calling whichever Models).