douminfu8033 2016-11-20 20:11
浏览 61
已采纳

Yii2:它是否有访问$ _REQUEST的抽象?

Does Yii2 have an abstraction for $_REQUEST? I don't seem to find it, so maybe there is a reason for not having it?

Maybe I have to figure it out manually by just using Yii::$app->request->get() and Yii::$app->request->post()?

  • 写回答

1条回答 默认 最新

  • doudu2515 2016-11-22 09:34
    关注

    Yii1 had it, in Yii2 it's gone.

    You could just mimic old behavior with a adapted Request class though:

    class Request extends \yii\web\Request {
        /**
         * for compatibility with yii1 request->getParam()
         */
        public function getParam($name, $defaultValue = NULL) {
            return isset($_GET[$name]) ? $_GET[$name] : (isset($_POST[$name]) ? $_POST[$name] : $defaultValue);
        }
    } 
    

    You need to override the request application component setting to use your own class then.

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

报告相同问题?

悬赏问题

  • ¥15 基于OPENCV的人脸识别
  • ¥20 51单片机学习中的问题
  • ¥30 Windows Server 2016利用兩張網卡處理兩個不同網絡
  • ¥15 Python中knn问题
  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!