Yii Programming Development common call tips and yii tips

Source: Internet
Author: User

Yii Programming Development common call tips and yii tips

This example summarizes common call techniques for Yii programming and development. We will share this with you for your reference. The details are as follows:

1. Set cookie:

$ Cookie = new CHttpCookie ('mycooker', 'This is my cooker'); $ cookie-> expire = time () + 60*60*24*30; // there is a time limit of 30 days. Yii: app ()-> request-> cookies ['mycookier'] = $ cookie;

2. Read cookie:

$cookie = Yii::app()->request->getCookies();echo $cookie['mycookie']->value;

3. Destroy cookie:

$cookie = Yii::app()->request->getCookies();unset($cookie[$name]);

4. Get the updated data id

$post->save();$id = $post->attributes['id'];

5. Get the inserted data id

$id = Yii::app()->db->getLastInsertID();

6. get the get and post data.

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

7. Obtain the IP address

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

8. Get the url of the previous page to return

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

9. Get the current url:

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

10. Get the current home url:

Yii::app()->homeUrl;

11. Get the current return url:

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

12. Project path:

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

13. project directory:

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

14. Obtain the ID method of the current controller in view:

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

15. Obtain the ID method of the current action in view:

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

16. yii judgment and submission method:

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

17. Get the current domain name:

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

18. Obtain the physical path of the proteced directory:

YII::app()->basePath;

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.