Yii method for getting the current url and domain name _ PHP Tutorial

Source: Internet
Author: User
Yii method for obtaining the current url and domain name. Yii: how to get the current url and domain name this article describes how Yii gets the current url and domain name. Share it with you for your reference. Details: assume that the access location Yii of our current page obtains the current url and domain name.

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:

The code is as follows:

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

Result: http: // localhost

2. get the current URL (except the domain name:

The 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:

The code is as follows:

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

Result:/CMS/public/index. php

4. get the root directory address (except the domain name:

The code is as follows:

Echo Yii: app ()-> homeUrl;

Result:/CMS/public/index. php

5,

The 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. Application example: Home)

II,

7. obtain the IP address of YII:

The code is as follows:

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

8. Yii judgment and submission method:

The code is as follows:

Yii: app ()-> request-isPostRequest;

9. physical path of the proteced Directory:

The code is as follows:

Yii: app ()-> basePath;

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

The code is as follows:

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

11. get the current controller ID:

The code is as follows:

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

12. Project path:

The code is as follows:

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

13. Yii obtains get and post data:

The 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:

The code is as follows:

Ccontroler-> refresh ();

I hope this article will help you design php programs based on the YII Framework.

Examples in this article describes how Yii obtains the current url and domain name. Share it with you for your reference. The details are as follows: assume that the access location of the current page is...

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.