simple PHP code sample to serve backbone.js

前端 未结 3 850
盖世英雄少女心
盖世英雄少女心 2021-02-02 16:33

Experience level: newbie.

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 bee

3条回答
  •  自闭症患者
    2021-02-02 16:52

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

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

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

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

    3. 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:

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

提交回复
热议问题