Method for Yii2 to obtain the URL. Method for yii2 to obtain the url

Source: Internet
Author: User

Method for Yii2 to obtain the URL. Method for yii2 to obtain the url


1. Obtain the host information in the url:

Example: http://www.nongxiange.com/product/2.html

Yii::$app->request->getHostInfo();

Results: http://www.nongxiange.com

 

2. Obtain the path information in the url (excluding host and parameters ):

Example: http://www.nongxiange.com/product/2.html? Isnew = 1

Yii::$app->request->getPathInfo()

Result: product/2.html

 

3. Obtain the url (including parameters) that does not contain host information ):
Example: http://www.nongxiange.com/product/2.html? Isnew = 1

Yii::$app->request->url

Result: product/2.html? Isnew = 1

 

4. Obtain the complete url (including host and parameters ):

Example: http://www.nongxiange.com/product/2.html? Isnew = 1

Yii::$app->request->getHostInfo().Yii::$app->request->url;

Result: http://www.nongxiange.com/product/2.html? Isnew = 1

5. Just retrieve the parameter section in the url:
Example: http://www.nongxiange.com/product/2.html? Isnew = 1

 Yii::$app->request->queryString

Result: isnew = 1.

6. Get the value of a parameter, such as id
Example: http://www.nongxiange.com/user? Id = 12345

Yii::$app->request->getQueryParam('id')

Result: 12345

  

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.