ThinkPHP6.0 GET 請求和POST 請求


ThinkPHP6 請求
要使用請求對象必須使用門面方式( think\facade\Request類負責 )調用

可以通過Request對象完成全局輸入變量的檢測、獲取和安全過濾

支持$_GET、$_POST、$_REQUEST、$_SERVER、$_SESSION、$_COOKIE、$_ENV等系統變量,以及文件上傳信息

1、GET 請求

PARAM類型變量是框架提供的用於自動識別當前請求的一種變量獲取方式,是系統推薦的獲取請求參數的方法

param方法會把當前請求類型的參數和路由變量以及GET請求合並,並且路由變量是優先的

controller代碼

public function edit(){

print_r( $_GET ); // 原生get接收

print_r( Request::param() ); // 獲取當前請求的所有變量

print_r( Request::param('id') ); // 獲取當前請求的id變量

print_r( Request::get() );

}

2、POST 請求

controller代碼

public function edit(){

$id = Request::param('id');

$shop = Db::table('shop_goods')->where('id',$id)->find();

$cat = Db::table('shop_cat')->where('status',1)->select();

View::assign([

'shop' => $shop,

'cat' => $cat

]);

return View::fetch();

}

public function edits(){

// print_r( Request::param() );

// print_r( Request::post() );

 

$all = Request::param();

$update = Db::table('shop_goods')->where('id',$all['id'])->update($all);

if($update){

echo json_encode(['code'=>0,'msg'=>'修改成功']);

}else{

echo json_encode(['code'=>1,'msg'=>'修改失敗']);

}

}

文章來自 www.dg-haiyue.cn


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM