Home  >  Article  >  PHP Framework  >  How to get the current url and domain name in yii

How to get the current url and domain name in yii

王林
王林forward
2020-09-28 17:20:422945browse

How to get the current url and domain name in yii

Assume that the access address of our current page is:

http://localhost/CMS/public/index.php?r=news&id=1

(Recommended tutorial: yii)

1,

1. Get the current domain name:

echo Yii::app()->request->hostInfo;

Result:

http://localhost

2. Get the current URL (except domain name):

echo Yii::app()->request->getUrl();

Result:

/CMS/public/index.php?r=news&id=1

3. Get the homepage address (except the domain name):

echo Yii::app()->user->returnUrl;

Result:

/CMS/public/index.php

4. Get the root directory address (except the domain name):

echo Yii::app()->homeUrl;

Result:

/CMS/public/index.php

5,

echo Yii::app()->request->baseUrl;

Result:

/CMS/public

6. Get the relative address of the website root directory:

echo Yii::app()->baseUrl;

Result:

/CMS/public

(Note: If you directly use this method to point to the root directory of the website, it is best to add a "/" after it, because sometimes if you do not add "/", it may not point to the root directory of the website correctly. Application examples : c59c70dfd7b9778b4e1cf39880794aaebaseUrl ;?>/">Home5db79b134e9f6b82c0b36e0489ee08ed )
2.
7. YII obtains the IP address :

Yii::app()->request->userHostAddress;

8. Yii determines the submission method:

Yii::app()->request-isPostRequest;

9. The physical path of the protected directory:

Yii::app()->basePath;

10. Get the url of the previous page to return:

Yii::app()->request->urlReferrer;

11. Get the current controller ID:

Yii::app()->getController()->getAction()->id;

12. Project path:

dirname(Yii::app()->BasePath);

13. Yii gets the data from get and post:

Yii::app()->request->getParam('id');

3.

14. How to set the time zone in Yii:

You can set the time zone in 'timeZone'=>'Asia/Chongqing' in config/main.php

15. Prevent duplicate submissions:

Ccontroler->refresh();

The above is the detailed content of How to get the current url and domain name in yii. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete