Yii gets the current URL and domain name

Source: Internet
Author: User

If our current page's access address is: http://localhost/CMS/public/index.php?

R=news&id=1
One,
1, get the current domain name: Echoyii::app ()->request->hostinfo;
Result: http://localhost

2, gets (except for the domain name) the current Url:echoyii::app ()->request->geturl ();
Result:/cms/public/index.php?r=news&id=1

3, get (except for the domain name) home address: Echoyii::app ()->user-> RETURNURL;
Result:/cms/public/index.php

4, get (except for the domain name) root folder address: Echoyii::app ()->homeurl;
Result:/cms/public/index.php

5, Echoyii::app ()->request->baseurl;
Result:/cms/public

6, get the site root folder relative address: Echo Yii::app ()->baseurl;
Result:/cms/public (Note: If you are using this method to point to the site root folder, it is best to add a "/" after it, because it is sometimes assumed that you do not join "/", it may not be correct to point to the site root folder.) Application Example: <ahref= "<?

php echo Yii::app ()->baseurl;? >/">Home</a>)

Two
7,Yii get IP Address:yii::app ()->request->userhostaddress;

8. Yii Inference Submission Method: Yii::app ()->request-ispostrequest;

9. Physical path of proteced folder: Yii::app ()->basepath;

10. Get the URL of the previous page to return: Yii::app ()->request->urlreferrer;

11. Get current controller Id:yii::app ()->getcontroller ()->getaction ()->id;

12, Project path: DirName (Yii::app ()->basepath);

13, Yii get get,post come over data: Yii::app ()->request->getparam (' id ');


Three
14, Yii How to set the time zone:
Able to set time zones in config/main.php ' timeZone ' = ' asia/chongqing '

15, Prevent repeated submission:Ccontroler->refresh ();

16, call the YII Framework Jquery:yii::app ()->clientscript->registercorescript (' jquery ');

17. Project Path: DirName (Yii::app ()->basepath)

Yii gets the current URL and domain name

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.