您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
webman-請求-獲取請求參數get
发布时间:2022-01-16 21:05:22编辑:雪饮阅读()
實例:
<?php
namespace app\controller;
use support\Request;
class User
{
public function hello(Request $request)
{
//获取整个get数组 如果请求没有get参数则返回一个空的数组。
$params["get"]=$request->get();
//获取get数组的某一个值 如果get数组中不包含这个值则返回null。
$params["get name"]=$request->get("name");
//获取get数组的某一个值 你也可以给get方法第二个参数传递一个默认值,如果get数组中没找到对应值则返回默认值.
$params["get name1"]=$request->get("name1","name1 is empty");
//輸出默認在沒有-d選項即調試模式時候的命令終端上
var_dump($params);
}
}
實例運行並被訪問時:
[root@localhost webman]# /usr/local/php734/bin/php start.php restart
Workerman[start.php] restart
Workerman[start.php] is stopping ...
Workerman[start.php] stop success
----------------------------------------- WORKERMAN -----------------------------------------
Workerman version:4.0.26 PHP version:7.3.4
------------------------------------------ WORKERS ------------------------------------------
proto user worker listen processes status
tcp root webman http://0.0.0.0:8787 4 [OK]
tcp root monitor none 1 [OK]
---------------------------------------------------------------------------------------------
Press Ctrl+C to stop. Start success.
array(3) {
["get"]=>
array(1) {
["name"]=>
string(3) "tom"
}
["get name"]=>
string(3) "tom"
["get name1"]=>
string(14) "name1 is empty"
}
訪問地址如:http://192.168.43.170:8787/user/hello?name=tom
如果我以name2來獲取時:
$params["get name"]=$request->get("name2");
終端:
/www/wwwroot/webman/webman/app/controller/User.php update and reload
Workerman[start.php] reloading
array(3) {
["get"]=>
array(1) {
["name"]=>
string(3) "tom"
}
["get name"]=>
NULL
["get name1"]=>
string(14) "name1 is empty"
}
关键字词:webman,請求,get