duanluanlang8501 2010-12-21 11:56
浏览 37
已采纳

PHP Tonic Services - 在同一服务中多次使用相同的动词

I started looking at the Tonic Restful Services framework and I really think it's a very nice framework. The problem is that I cannot find much resources apart from the examples in order to see possible ways of using it.

I would like for example to know if I could use the POST verb more than one time in a single resource and if there is some sort of annotation that could allow me to do that. For example JAX-RS have the @Action annotation.

I really do not have a lot of experience with REST or PHP so I really need your help.

Thank you in advance.

  • 写回答

1条回答 默认 最新

  • dtihe8614 2012-04-09 23:49
    关注

    No, you cannot. But you can route your posts using another variable in your posts requests. Just make sure to clean methods name for security reasons...

    something like this.

       /**
         * Handle a POST request for this resource
         * @param Request request
         * @return Response
         */
        function post($request) {
    
            if (isset($_POST['method'])) {
               return $this->$method($request, $name);
            }
    
        } 
    
        function post_one($request) {
           // your code here
        }
    
        function post_two($request) {
           // your code here
        }
    
        //...and so on...
    

    If you want to check if method exists, you could use something like

    if (method_exists('controller_name', 'method_name'));
    

    But that's another topic. http://php.net/manual/en/function.method-exists.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型