Use of Yii2request

Source: Internet
Author: User
: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.