【问题标题】:Restler 3, php, verbs. How work path?Restler 3,php,动词。工作路径如何?
【发布时间】:2013-08-02 13:15:55
【问题描述】:

我有问题。 Restler 3 中的工作路径如何?

class eventos {
function index($desde=0, $hasta=0) {}

function get($num, $p2='optional') {
       if($p2 != 'attend'){}
       else{}
    }

function post($num, $p2, $request_data = null){

       if($p2 == 'comment'){}
       if($p2 == 'attend'){}

    }

}

我需要:

GET ...public/index.php/eventos/(带2个参数)好的!

POST ...public/index.php/eventos/(4-5个参数)它是如何工作的?

GET ...public/index.php/eventos/{id} 好的!

GET ...public/index.php/eventos/{id}/attend 不行!!!如果 ...eventos/x?p2=attend 可以工作,但我不想要这个,我想要 ...eventos/x/attend

POST ...public/index.php/eventos/{id}/attend (X 参数) ok!

POST ...public/index.php/eventos/{id}/comment(带2个参数)ok!

谢谢!

【问题讨论】:

    标签: post path restler


    【解决方案1】:

    (我假设“2个参数”是指查询字符串参数)

    对于 Restler 3,路径中的参数(例如 eventos /x /attend)是必需的。您希望成为可选的任何内容都来自查询字符串。

    由于您已将 GET 的 $p2 指定为可选,因此它只能来自查询字符串:eventos/x?p2=attend。

    如果您想覆盖它并返回到 Rester 2 方法,您可以按照此处指定的方式关闭此自动路由:http://restler3.luracast.com/examples/_006_routing/readme.html

    至于您关于 4-5 参数的 POST 问题,如果您需要它们:

    function post($id, $p1, $p1, $p3, $p4){
    

    ...或者如果它们是可选的:

    function post($id, $p2, $request_data = null){
    

    然后将 POST 正文中的 4-5 个参数传递给 URL eventos/attend 或 eventos/comment。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-06
      • 1970-01-01
      • 1970-01-01
      • 2010-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多