thinkphp 參數傳遞方式(基礎)

來源:互聯網
上載者:User

標籤:ram   擷取參數   總結   att   pre   res   ret   get   函數   

我今天下午主要學習了thinkphp5.0的路由部分,我下面總結一下我主要學習到的知識點:

路由定義:

有兩種方式:

(1).動態註冊:

eg:
  Route::rule(‘hello‘,‘index/index/hello‘,‘GET‘);

(2)配置式:

eg:
return [
‘__pattern__‘ => [
‘name‘ => ‘\w+‘,
],
‘[hello]‘ => [
‘:id‘ => [‘index/hello‘, [‘method‘ => ‘get‘], [‘id‘ => ‘\d+‘]],
‘:name‘ => [‘index/hello‘, [‘method‘ => ‘post‘]],
],
];

請求類型:
 
類型 描述
GET GET請求
POST POST請求
PUT PUT請求
DELETE DELETE請求
* 任何請求類型

eg:
Route::get(‘new/:id‘,‘News/read‘); // 定義GET請求路由規則Route::post(‘new/:id‘,‘News/update‘); // 定義POST請求路由規則Route::put(‘new/:id‘,‘News/update‘); // 定義PUT請求路由規則Route::delete(‘new/:id‘,‘News/delete‘); // 定義DELETE請求路由規則Route::any(‘new/:id‘,‘News/read‘); // 所有請求都支援的路由規則

擷取參數的方法 [三種 ]:
1).方法內變數的對應

public function hello($id,$name)
{
echo $id;
echo $name;
}

2).Request對象
Requeset::instance=>param();//擷取所有參數[ 結果類型數組],不分請求類型;
Requeset::instance=>param(‘name‘);//擷取單個參數[即:直接填寫變數名即可];
Requeset::instance=>get();//擷取?後面的參數;
Requeset::instance=>route();//擷取路由裡面的參數;
Requeset::instance=>post();//擷取post請求參數
eg:
public function hello()
{
$res=Request::instance()->param();
var_dump($res);
}

依賴注入方式
public function hello(Request $request)
{
$res=$request->param();
var_dump($res);
}


3).使用input助手函數
input(‘param‘); //擷取所有結果數組
input(‘param.name‘); //擷取name
input(‘get.name‘); //擷取post方式
input(‘get.name‘); //擷取get方式


 
 
 





 

 

thinkphp 參數傳遞方式(基礎)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.