: This article describes how to use Yii2request. if you are interested in the PHP Tutorial, refer to it. Common get and pst requests
$ Request = Yii: $ app-> request; $ get = $ request-> get (); // equivalent to: $ get =$ _ GET; $ id = $ request-> get ('id'); // equivalent to: $ id = isset ($ _ GET ['id'])? $ _ GET ['id']: null; $ id = $ request-> get ('id', 1); // equivalent: $ id = isset ($ _ GET ['id'])? $ _ GET ['id']: 1; // added the default value $ post = $ request-> post (); // equivalent to: $ post =$ _ POST; $ name = $ request-> post ('name'); // equivalent to: $ name = isset ($ _ POST ['name'])? $ _ POST ['name']: null; $ name = $ request-> post ('name', ''); // equivalent: $ name = isset ($ _ POST ['name'])? $ _ POST ['name']: ''; // The default value is added.
Determining request attributes
$ Request = Yii: $ app-> request; if ($ request-> isAjax) {// Determine whether the request is an AJAX request} if ($ request-> isGet) {// Determine whether the request is a GET request} if ($ request-> isPost) {// Determine whether the request is a POST request} if ($ request-> isPut) {// Determine whether the request is a PUT request} if ($ request-> isSecureConnection) {// Determine whether the request is an https request}
GET request header information
// $ Headers is an object of yii \ web \ HeaderCollection $ headers = Yii: $ app-> request-> headers; // return all information in the header $ accept = $ headers-> get ('accept '); if ($ headers-> has ('User-agent ')) {// Get User-Agent}
Obtain user client information
$userHost = Yii::$app->request->userHost; $userIP = Yii::$app->request->userIP;
The above introduces the use of Yii2 request, including the content, hope to be helpful to friends interested in PHP tutorials.