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 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100