使用Phil Sturgeon 的REST_Controller
Backbone.js 集合:
define([
'jquery',
'underscore',
'backbone',
'models/project/ProjectModel2'
], function($, _, Backbone, ProjectModel2){
var ProjectsCollection2 = Backbone.Collection.extend({
initialize: function() {
this.on('all', function(e) { console.log("ProjectCollectiona: " + e); });
},
model: ProjectModel2,
url: "http://subdomain.domain.com/index.php/test/index"
});
return ProjectsCollection2;
});
Codeigniter 控制器:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require(APPPATH'.libraries/REST_Controller.php');
class Test extends REST_Controller {
public function index_get()
{
$this->response(array('success' => 'get'), 200);
}
public function index_post()
{
$this->response(array('success' => 'post'), 200);
}
}
通过 Chrome Inspector 输出的标头:
Request URL:http://subdomain.domain.com/index.php/test/index
Request Method:GET
Status Code:500 Internal Server Error
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Type:application/x-www-form-urlencoded
Cookie:__utma=218955780.1934049331.1355591749.1355591749.1355591749.1; __utmc=218955780; __utmz=218955780.1355591749.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); ci_session=a%3A5%3A%7Bs%3A10%3A%22session_id%22%3Bs%3A32%3A%22698c724d973d37b869d90ca059b326c5%22%3Bs%3A10%3A%22user_agent%22%3Bs%3A119%3A%22Mozilla%2F5.0+%28Macintosh%3B+Intel+Mac+OS+X+10_7_5%29+AppleWebKit%2F537.17+%28KHTML%2C+like+Gecko%29+Chrome%2F24.0.1312.52+Safari%2F537.17%22%3Bs%3A13%3A%22last_activity%22%3Bi%3A1358311296%3Bs%3A9%3A%22user_data%22%3Bs%3A0%3A%22%22%3B%7D164f4b5137bde1a0f31c3db5cc6723bf
Host:subdomain.domain.com
Referer:http://subdomain.domain.com/
User-Agent:Using Chrome on Mac
X-Requested-With:XMLHttpRequest
Response Headersview source
Connection:close
Content-Encoding:gzip
Content-Length:20
Content-Type:text/html
Date:Wed, 16 Jan 2013 04:41:36 GMT
Server:Apache
Vary:Accept-Encoding
两个问题:
第一个很明显,在为 Codeigniter 控制器定义 URL 时得到 500。我是否错误地定义了 URL?
第二个令人困惑,我试图从库中自动加载 REST_Controller.php,当我运行上面的代码时,我得到一个空白浏览器,Chrome 检查器中也没有任何内容。
非常感谢任何指导。