1. Set cookies:

$cookie=new chttpcookie ("mycookie", "this is my cookie");
$cookie->expire=time () + 60 * 60 * 24 * 30;//limited period of 30 days
yii ::app ()->request->cookies ["mycookie"]=$cookie;

2. Read cookies:

$cookie=yii ::app ()->request->getcookies ();
echo $cookie ["mycookie"]->value;

3. Destroy cookies:

$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 data from get and post

yii ::app ()->request->getparam ("id");

7. Get 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. Get the id method of the current controller in the view:

yii ::app ()->request->baseurl;

15. Get the id method of the current action in the view:

yii ::app ()->getcontroller ()->getaction ()->id;

16. Yii judges the submission method:

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

17. Get the current domain name:

yii ::app ()->request->hostinfo;

18. Get the physical path of the protected directory:

yii ::app ()->basepath;
  • Previous Summarize six encryption technologies and code commonly used in Java
  • Next Detailed explanation of relation data query and statistical function usage in Yii