是否有一种 MVC 方法,使用 PHP 作为模型和控制器,使用纯 HTML 作为视图,同时使用 JSON 在它们之间传输数据?
我只是想知道是否有任何现有框架或者有人有使用完全静态 HTML 模板的经验,这些模板填充了通过服务器的 JSON 提供的数据。
支持 JavaScript 的 HTML 页面应该扮演视图的角色,而控制器和模型则由服务器端的 PHP 处理。
视图将通过 JSON-RPC 或来自模型的类似数据进行查询,然后通过操作 DOM 来呈现结果。
我非常喜欢这个想法,几周前它就出现在我的脑海中,但我从未在网络上找到任何与该想法甚至现有框架相关的经验。
但也许我只是谷歌搜索的菜鸟?
也许你们中的一个人可以帮助我。
提前致谢 祝你今天过得愉快!
本杰明
I just wondered if there is any existing framework or someone has experiences with using entirely static HTML templates that get filled with data provided via JSON from the server.
The HTML pages with JavaScript support should fulfill the role of the View whereas Controller and Model are handled by the PHP on the server side.
Views would the query via JSON-RPC or similar data from the Model and then render the results by manipulating the DOM.
I pretty much like this idea, it came into my mind weeks ago but I never found something on the web experiences with that or even already existing framework.
But maybe I am just a noob at googling?
Maybe one of you can help me out here.
Thanks in advance
Have a nice day!
Benjamin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这种情况很有可能发生,并且经常出现在富客户端应用程序中。对应用程序的第一次调用会提供初始 UI,其中包含 JavaScript 文件中定义的任何行为。任何进一步的交互都是通过 Ajax 完成的。
对于服务器端,请查看
虽然这也可以是一个常规的 MVC 应用程序。 Json 或 XML 响应仍然可以被视为视图。您可以对控制器进行编码以返回适当的数据。
This is very much possible and often found with Rich Client Applications. The first call to the application delivers the initial UI with any behavior defined in JavaScript files. Any further interaction is done via Ajax.
For the serverside, have a look at
though this could just as well be a regular MVC application too. A Json or XML Response can still be considered a View. It's up to you to code your controllers to return appropriate data.
这几乎就是 Google 做很多事情的方式——在 Gmail 上查看源代码,看看他们在 HTML 中返回了多少数据。
这就是所谓的阿贾克斯。 (这并不是说听起来太讽刺了 - Ajax 不一定像这样工作,但基于 ajax 的应用程序将通过 JavaScript 而不是通过服务器端代码完成大量渲染逻辑。)
That's pretty much how Google do a lot of their stuff - do a view source on Gmail to see how much data they return in the HTML.
It's called Ajax. (That's not meant to sound too sarcastic - Ajax doesn't necessarily work like this, but ajax-based apps will do a lot of the rendering logic via JavaScript rather than via server-side code.)
您需要一个不会限制您处理 MVC 应用程序视图组件的任何特定方式的框架,我认为 Zend Framework 将是您的最佳选择。它还与 DOJO 进行了很好的集成,这使得您可以更轻松地实现您的需求。
You need a framework that doesn't limit you to any specific way of handling the view component of your MVC application and I think Zend Framework would be your best choice. It also has a great integration with DOJO and that makes it a lot easier to achieve what you need.