Yii how to get the current URL and domain name _php tutorial

Source: Internet
Author: User
Tags get ip yii

Yii method to get the current URL and domain name


The examples in this article describe how Yii obtains the current URL and domain name. Share to everyone for your reference. Specific as follows:

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

One

1. Get the current domain name:

The code is as follows:

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

Results: http://localhost

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

The code is as follows:

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

Results:/cms/public/index.php?r=news&id=1

3, get (except the domain name) home address:

The code is as follows:

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

Results:/cms/public/index.php

4, get (except the domain name) root directory address:

The code is as follows:

Echo Yii::app ()->homeurl;

Results:/cms/public/index.php

5.

The code is as follows:

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

Results:/cms/public

6. Get site root directory relative address: Echo Yii::app ()->baseurl;

Results:/cms/public (Note: If you point directly to the Web site root directory, it is a good idea to add a "/" after it, because sometimes if you do not add "/", you may not be able to point to the Web site root directory correctly.) application Example: Home)

Two

7, Yii get IP address:

The code is as follows:

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

8, Yii judgment submission method:

The code is as follows:

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

9. The 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 Gets Get,post data:

The code is as follows:

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

Three

14, Yii How to set the time zone:

Can be in config/main.php ' timeZone ' = ' asia/chongqing ', set time zone

15. Prevent Duplicate Submissions:

The code is as follows:

Ccontroler->refresh ();

It is hoped that this article is helpful to the PHP program design based on YII framework.

http://www.bkjia.com/PHPjc/1012985.html www.bkjia.com true http://www.bkjia.com/PHPjc/1012985.html techarticle Yii How to get the current URL and domain Name This example describes how Yii obtains the current URL and domain name. Share to everyone for your reference. As follows: Suppose our current page accesses the site ...

  • Related Article

    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.