您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
3-2 控制器之请求处理
发布时间:2023-04-26 21:57:03编辑:雪饮阅读()
-
其实都和thinkphp是差不多的(thinkphp5以后)
例如请求如
http://www.xyyii.com/basic/web/index.php?r=hello/index&id=1
则有控制器如:
<?php
namespace app\controllers;
use yii\web\Controller;
class HelloController extends Controller{
public function actionIndex(){
$request=\YII::$app->request;
echo "get方法获取参数:";
echo $request->get('id');
echo "<hr/>";
echo "get方法获取参数,当指定参数不存在即返回默认值,这里是20:";
echo $request->get('id2',20);
echo "<hr/>";
echo "isGet判断当前请求方法是否是get方法:";
if($request->isGet){
echo "当前请求方式是get";
}
echo "<hr/>";
echo "isPost判断当前请求方法是否是post方法:";
if($request->isPost){
echo "当前请求方式是post";
}
echo "<hr/>";
echo "userIp据说是源代码放在真实服务器上面才能获取到用户来访时候用户的来源ip:";
echo $request->userIp;
}
}
关键字词:请求
上一篇:3-1 控制器的创建(yii)