Home  >  Article  >  Backend Development  >  How to get URL in Yii2 framework

How to get URL in Yii2 framework

巴扎黑
巴扎黑Original
2017-07-24 10:34:113665browse


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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn