How to get URL in Yii2 framework

巴扎黑
Release: 2023-03-13 13:18:01
Original
3677 people have browsed it


1. Get the host information in the url:

For example:

Yii::$app->request->getHostInfo();
Copy after login

Result:

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

For example:

Yii::$app->request->getPathInfo()
Copy after login

Result: product/2.html

3. Get the url that does not contain host information (including parameters):
For example:

Yii::$app->request->url
Copy after login

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;
Copy after login

Result:

5. Just want to get the parameter part of the url:
For example:

 Yii::$app->request->queryString
Copy after login

Result: isnew=1

6. Get the value of a certain parameter, such as id
For example:

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template