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