The examples in this article summarize common calling techniques in Yii programming development. Share it with everyone for your reference, the details are as follows:
1. Set cookie:
$cookie = new CHttpCookie('mycookie','this is my cookie'); $cookie->expire = time()+60*60*24*30; //有限期30天 Yii::app()->request->cookies['mycookie']=$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 updated data id
$post->save(); $id = $post->attributes['id'];
5. Get the inserted data id
$id = Yii::app()->db->getLastInsertID();
6. Get the data from get and post
Yii::app()->request->getParam('id');
7. Get the ip address
Yii::app()->request->userHostAddress;
8. Get the IP address of the previous page url to return
Yii::app()->request->urlReferrer;
9. Get the current url:
Yii::app()->request->url;
10. Get Current home url:
Yii::app()->homeUrl;
11. Get current return url:
Yii::app()->user->returnUrl;
12 . Project path:
dirname(Yii::app()->BasePath);
13. Project directory:
Yii::app()->request->baseUrl;
##14. Get the ID method of the current controller in the view:
Yii::app()->request->baseUrl;
Yii::app()->getController()->getAction()->id;
16. yii determines the submission method:
Yii::app()->request->isPostRequest;
Yii::app()->request->hostInfo;
YII::app()->basePath;