Yii2如何在控制器中接收get,post数据?

laravel支持在actionIndex()括号里面传参,然后直接在方法里面输出,但是yii不行

yii的get,post需要使用request请求组件

public function actionIndex()
{
    $request = \Yii::$app->request;
    //echo $request->get('id', 1);                         //get获取。可以通过第二个参数设置默认值
    //$username = $request->post('username', '李彦宏');    //post获取。可以通过第二个参数设置默认值
    //echo $username;

    //var_dump($request->isGet);       //判断是不是get提交
    //var_dump($request->isPost);      //判断是不是post提交

    $request->userIp;    //获取用户IP地址
}

猜你喜欢

转载自blog.csdn.net/qq_38083665/article/details/80723307