Yii gets the current url and domain name, And yii gets the current url
This example describes how Yii obtains the current url and domain name. Share it with you 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
I,
1. Obtain the current domain name:Copy codeThe Code is as follows: echo Yii: app ()-> request-> hostInfo;
Result: http: // localhost
2. Get the current URL (except the domain name:Copy codeThe Code is as follows: echo Yii: app ()-> request-> getUrl ();
Result:/CMS/public/index. php? R = news & id = 1
3. Obtain the home address (except the domain name:Copy codeThe Code is as follows: echo Yii: app ()-> user-> returnUrl;
Result:/CMS/public/index. php
4. Get the root directory address (except the domain name:Copy codeThe Code is as follows: echo Yii: app ()-> homeUrl;
Result:/CMS/public/index. php
5,Copy codeThe Code is as follows: echo Yii: app ()-> request-> baseUrl;
Result:/CMS/public
6. Obtain the relative address of the website root directory: echo Yii: app ()-> baseUrl;
Result:/CMS/public (Note: If you direct this method to the root directory of the Website, you 'd better add a "/" next to it, because sometimes if you do not add "/", it may not point to the root directory of the website correctly. Example: <a href = "<? Php echo Yii: app ()-> baseUrl;?> /"> Home </a>)
II,
7. Obtain the IP address of YII:Copy codeThe Code is as follows: Yii: app ()-> request-> userHostAddress;
8. Yii judgment and submission method:Copy codeThe Code is as follows: Yii: app ()-> request-isPostRequest;
9. physical path of the proteced directory:Copy codeThe Code is as follows: Yii: app ()-> basePath;
10. Get the url of the previous page to return:Copy codeThe Code is as follows: Yii: app ()-> request-> urlReferrer;
11. Get the current controller ID:Copy codeThe Code is as follows: Yii: app ()-> getController ()-> getAction ()-> id;
12. Project path:Copy codeThe Code is as follows: dirname (Yii: app ()-> BasePath );
13. Yii obtains get and post data:Copy codeThe Code is as follows: Yii: app ()-> request-> getParam ('id ');
III,
14. How to set the time zone for Yii:
You can set the time zone in 'timezone '=> 'Asia/chongqing' in config/main. php.
15. prevent repeated submission:Copy codeThe Code is as follows: Ccontroler-> refresh ();
I hope this article will help you design php programs based on the YII framework.