douzhi4056 2017-03-28 14:53
浏览 28

如何使用REST Web服务在YII2中创建用户名和密码身份验证

I wish to create Web Services for each single task so that i do not replicated or rewrite code for same task for different platforms.

  • 写回答

1条回答 默认 最新

  • douhua1760 2017-03-29 05:21
    关注

    What you should do is have a REST file in your model with all the curl operations performed in it for various functions like get data and post data.After that use a object of this class to get and receive parameters if needed.

        $rest_obj = new RestService("web service URL", 'param1', 'param2');
        $rest_obj->requestName = 'webservice controller name';
        $rest_obj->requestData = '';
        $rest_obj->querydata = $data['request_params'];
        $rest_obj->requestType = "html";
        $rest_obj->responseType = "json";
        $rest_obj->getData();
        $fields_array = $rest_obj->response;  
    

    If you do this then I think you can use this web service for n number of frontends. Web services are basically another Yii app with connection to the database and basically act as backend to a number of frontends.So my advice would be to create a controller and a model to fetch data from the db and connect it using the rest service I gave before and everything should work fine.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器