Home >php教程 >PHP开发 >A collection of common calling techniques in Yii programming development

A collection of common calling techniques in Yii programming development

高洛峰
高洛峰Original
2016-12-30 14:47:361348browse

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;

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

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

16. yii determines the submission method:

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

17. Gets the current domain name:

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

18. Get the physical path of the protected directory:

YII::app()->basePath;

I hope this article will be helpful to everyone’s PHP programming based on the Yii framework.

For more related articles on common calling techniques in Yii programming development, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn