2011-11-12 32 views
2

我正在使用Luracast Restler API框架,並想知道如何組織類結構來創建這種類型的路由。如何組織Luracast Restler類來創建相關的路由端點?

webroot/user/:id/ 
webroot/user/:id/profile 
webroot/user/:id/tweets 

對於使用GET,PUT,POST的可能性,刪除每個:

Class user(){ 
function get($id){ 
    Do something when GET/webroot/user/:id/ 
} 
function put($data){ 
    Do something when PUT/webroot/user/:data/ 
} 
} 
Class profile(){ 
function get($id){ 
    Do something when GET/webroot/user/:id/profile 
} 
} 
Class tweets(){ 
function get($id){ 
    Do something when GET/webroot/user/:id/tweets 
} 
} 

提前感謝!

+0

你嘗試過什麼到目前爲止?向一個你遇到過具體的問題嗎?官方的規範是什麼,你的課程是否適用? – hakre

回答

2

您需要使用自定義URL路由使用PHP文檔註釋。這是您的用例的修改示例。

Class User(){ 
function get($id){ 
    //Do something when GET /webroot/user/:id/ 
} 
function put($data){ 
    //Do something when PUT /webroot/user/:data/ 
} 
/** 
* @url GET /:id/profile 
*/ 
function profile($id){ 
    //get the profile for specified user 
} 
} 

您可以使用POST,DELETE,PUT替換方法以進行配置文件編輯。另請注意,您可以使用上述語法添加多條路線。

1

是否允許在其他CRUD方法上使用自定義路線?

/** 
* @url POST /create 
*/  
protected function post($request_data=NULL) { 
    return $this->dp->insert($this->_validate($request_data)); 
} 

我叫POST正確

Prepared POST URLRequest '<NSMutableURLRequest http://myserver.com/base/_006_crud/user>'. HTTP Headers: { 
    Accept = "application/json"; 
    "Content-Type" = "application/x-www-form-urlencoded"; 
}. HTTP Body: ssoid=123&ssotype=facebook&crudID=0&ssoname=mickey. 

,但是當我從我的代碼中調用我得到一個404 「Not Found」 錯誤」

response body: { 
    "error": { 
    "code": 404, 
    "message": "Not Found" 
    } 
}