1. Get the host information in the url:
For example:
Yii::$app->request->getHostInfo();
Result:
2. Get the path information in the url (excluding host and parameters):
For example:
Yii::$app->request->getPathInfo()
Result: product/2.html
3. Get the url that does not contain host information (including parameters):
For example:
Yii::$app->request->url
Result: product/2. html?isnew=1
4. Get the complete url (including host and parameters):
For example:
Yii::$app->request->getHostInfo().Yii::$app->request->url;
Result:
5. Just want to get the parameter part of the url:
For example:
Yii::$app->request->queryString
Result: isnew=1
6. Get the value of a certain parameter, such as id
For example:
Yii::$app->request->getQueryParam('id')
Result: 12345
The above is the detailed content of How to get URL in Yii2 framework. For more information, please follow other related articles on the PHP Chinese website!