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;