Home > php教程 > PHP开发 > body text

A collection of common calling techniques in Yii programming development

高洛峰
Release: 2016-12-30 14:47:36
Original
1287 people have browsed it

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;
Copy after login

2. Read cookie:

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

3. Destroy cookie:

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

4. Get updated data id

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

5. Get the inserted data id

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

6. Get the data from get and post

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

7. Get the ip address

Yii::app()->request->userHostAddress;
Copy after login

8. Get the IP address of the previous page url to return

Yii::app()->request->urlReferrer;
Copy after login

9. Get the current url:

Yii::app()->request->url;
Copy after login

10. Get Current home url:

Yii::app()->homeUrl;
Copy after login

11. Get current return url:

Yii::app()->user->returnUrl;
Copy after login

12 . Project path:

dirname(Yii::app()->BasePath);
Copy after login

13. Project directory:

Yii::app()->request->baseUrl;
Copy after login
Copy after login

##14. Get the ID method of the current controller in the view:

Yii::app()->request->baseUrl;
Copy after login
Copy after login

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

Yii::app()->getController()->getAction()->id;
Copy after login

16. yii determines the submission method:

Yii::app()->request->isPostRequest;
Copy after login

17. Gets the current domain name:

Yii::app()->request->hostInfo;
Copy after login

18. Get the physical path of the protected directory:

YII::app()->basePath;
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!