Home >Backend Development >PHP Tutorial >How to get the current url and domain name in Yii, get the current url in yii_PHP tutorial

How to get the current url and domain name in Yii, get the current url in yii_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:51:211076browse

How Yii obtains the current url and domain name, yii obtains the current url

The example in this article describes how Yii obtains the current url and domain name. Share it with everyone for your reference. The details are as follows:

Suppose the access address of our current page is: http://localhost/CMS/public/index.php?r=news&id=1

1.

1. Get the current domain name: Copy the code The code is as follows: echo Yii::app()->request->hostInfo;
Result: http://localhost

2. Get the current URL (except domain name): Copy code The code is as follows: echo Yii::app()->request->getUrl();
Result: /CMS/public/index.php?r=news&id=1

3. Get the homepage address (except domain name): Copy code The code is as follows: echo Yii::app()->user->returnUrl;
Result: /CMS/public/index.php

4. Get the root directory address (except domain name): Copy the code The code is as follows: echo Yii::app()->homeUrl;
Result: /CMS/public/index.php

5. Copy code The code is as follows: 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 use this method to directly point to the website root directory, it is best to add a "/" after it, because sometimes if you do not add "/", it may not point to the website root directory correctly. Application example: Home )

2.

7. YII obtains the IP address: Copy the code The code is as follows: Yii::app()->request->userHostAddress;

8. Yii determines the submission method: Copy code The code is as follows: Yii::app()->request-isPostRequest;

9. Physical path of the protected directory: Copy code The code is as follows: Yii::app()->basePath;

10. Get the url of the previous page to return: Copy code The code is as follows: Yii::app()->request->urlReferrer;

11. Get the current controller ID: Copy code The code is as follows: Yii::app()->getController()->getAction()->id ;

12. Project path: Copy code The code is as follows: dirname(Yii::app()->BasePath);

13. Yii gets the data from get and post: Copy the code The code is as follows: Yii::app()->request->getParam('id') ;

Three,

14. How to set the time zone in Yii:
You can set the time zone in config/main.php with 'timeZone'=>'Asia/Chongqing'

15. Prevent repeated submissions: Copy code The code is as follows: Ccontroler->refresh();

I hope this article will be helpful to everyone’s PHP programming based on the YII framework.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1013721.htmlTechArticleYii's method of obtaining the current url and domain name, yii's method of obtaining the current url. This article describes how Yii obtains the current url and domain name. method. Share it with everyone for your reference. The details are as follows: Suppose we...
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