你如何组织 Luracast Restler 类来创建相关的路由端点? [英] How do you organize Luracast Restler classes to create related route endpoints?

查看:23
本文介绍了你如何组织 Luracast Restler 类来创建相关的路由端点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Luracast Restler API 框架,想知道如何组织类结构来创建这种风格的路线.

I am working with Luracast Restler API framework and am wondering how to organize the class structures to create this style of route.

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

可以为每个使用 GET、PUT、POST、DELETE:

With the possibility of using GET, PUT, POST, DELETE for each:

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
 }
}

提前致谢!

推荐答案

您需要使用 PHP Doc 注释使用自定义 url 路由.这是您的用例的修改示例.

You need to use custom url routing using the PHP Doc comments. Here is the modified example for your use case.

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 以进行配置文件编辑.另请注意,您可以使用上述语法添加多个路由.

You can replace the method with POST, DELETE, PUT for profile editing. Also note that you can add more than one route using the syntax above.

这篇关于你如何组织 Luracast Restler 类来创建相关的路由端点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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