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

查看:238
本文介绍了你如何组织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文档注释使用自定义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天全站免登陆