简单的PHP code样品Backbone.js的服务 [英] simple PHP code sample to serve backbone.js

查看:130
本文介绍了简单的PHP code样品Backbone.js的服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经验等级:新手

托多斯演示使用localStorage的。这个问题是关于如何使用PHP来服务页面,而不是,假设一个MySQL数据库已经建立。

The backbone.js Todos demo uses localStorage. This question is about how to use PHP to serve the page instead, assuming that a MySQL DB has been set up.

我检查了PHP框架,比如codeIgniter却发现他们难以遵循,并可能矫枉过正我学习的目的。

I checked out PHP frameworks such as CodeIgniter but found them difficult to follow and possibly overkill for my learning purposes.

据我所知,REST API需要建立的概念。我真的寻找简单code样品。先谢谢了。

I understand the concept that a REST API needs to be set up. I am really looking for simple code samples. Thanks in advance.

更新:有一个完整的Backbone.js的教程的地方,包括如何连接到服务器端的PHP

Update: Is there a full backbone.js tutorial somewhere that includes a full working example of how to wire up to server side PHP?

推荐答案

最基本,最简单的方法(我知道)应该帮助您开始,将是:

The most basic and simple approach (I know of) that should help you to get started, would be:


  1. 鉴于你有一个模型/收藏,像一个网址定义它:

  1. Given you have a model / collection, define it with an url like:

resourceCollection:Backbone.Collection.extend({
      网址:'/page.php
    })

resourceCollection: Backbone.Collection.extend({ url: '/page.php' })

创建您的 page.php 文件(文档根目录),只需照顾的RewriteRules等你可以使用!

Create your page.php file (in the document root), just take care of RewriteRules etc. you may use!

现在我们必须确保我们可以得到正确的反应,PUT,POST和删除;所以我们必须检查请求的方法,例如与switch语句。案件将是GET,DELETE,PUT,POST:

Now we have to make sure that we can react properly on get, put, post and delete; so we have to check for the request method, e.g. with a switch statement. Cases would be GET, DELETE, PUT, POST:

开关( $ _ SERVER ['REQUEST_METHOD'] ){
   ...
}

switch($_SERVER['REQUEST_METHOD']){ ... }

这篇关于简单的PHP code样品Backbone.js的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆