2010-10-13 13:34
浏览 66

PHP Web设计:使用Smarty vs Rest使用jQuery

I've been trawling SO for a couple of hours tonight looking for some answers, but I've not found anything that really answers what I'm after. My apologies if it has, in fact, been answered already.

I'm designing a new website and I'm trying to decide on the architecture to use to serve the content. In the past, my websites have used PHP feeding data into Smarty templates.

However, recently at my work, I've been working on a Java web application where jQuery was used to retrieve the data from a RESTful API (which returned JSON), where HTML template pages were used as the base and javascript was used (utilising jQuery) to fill in the content.

My question:

The website I'm designing will be in PHP, but would it be better to construct (or use an existing) RESTful API or to continue on as I've done before feeding the data into Smarty templates?

Are there real benefits to one or the other, or does it just come down to developer preference/experience?

If it helps, the website will be for a church, where the content types will be CMS-like; news/announcements, wiki-like pages, and a limited type of social networking (for the minister to communicate with parishioners).

图片转代码服务由CSDN问答提供 功能建议

我今晚一直在搜索SO几个小时寻找答案,但我没有找到任何答案 这真的回答了我的追求。 事实上,如果它已经得到回答,我表示道歉。

我正在设计一个新网站,我正在尝试决定用于提供内容的架构。 过去,我的网站已经使用PHP将数据提供到Smarty模板中。

然而,最近在我的工作中,我一直在研究一个Java Web应用程序,其中使用jQuery来检索 来自RESTful API(返回JSON)的数据,其中HTML模板页面用作基础,并使用javascript(利用jQuery)填写内容。


我正在设计的网站将使用PHP,但构建(或使用现有的)RESTful API或在我将数据输入Smarty之前继续进行更好 模板?


如果有帮助, 该网站将用于教堂,其内容类型将类似于CMS; 新闻/公告,类似维基的页面,以及有限类型的社交网络(部长与教区居民沟通)。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dre26973 2010-10-13 15:08

    Short answer: It sounds like filling the content with JavaScript would not be useful in your case. Loading the data with JavaScript is adding a layer of complexity with minimal or no benefit (in your case). Take a look at CMSs and websites that have similar functionality to what you're doing. WordPress, Drupal, etc.

    For an example of when it might be useful to load data with JavaScript, check out the tags section on this site. When you search for a tag it queries the server without reloading the page. However, the initial tag list is loaded during the initial page load without any JS.

    Here are some cases where you might benefit from loading information with JS:

    • There is some data that will take longer to load. For example, you're getting data from a web service. Using the traditional method, you would need all the data you need for the page to be available before it can be displayed. If you loaded that data with JavaScript, the page could load and the slow data would appear when it returns. Realistically, you would probably just cache the data but this is just an example.
    • You will be getting more data as the user stays on the page. You might want to update the page without refreshing.
    • You want the user to be able to query more data without refreshing the page.
    • Your users have limited bandwidth (mobile).
    • This site has more guidelines:
    解决 无用
    打赏 举报

相关推荐 更多相似问题