Home> PHP Framework> YII> body text

How to use yii2 session

(*-*)浩
Release: 2019-11-05 13:43:41
Original
2706 people have browsed it

Session

The Session of Yii 2 is relatively simple, just operate it directly through \Yii::$app->session

How to use yii2 session

1) Add a session(Recommended learning:yii tutorial)

session; $session->set('smister_name' , 'myname'); $session->set('smister_array' ,[1,2,3]); ?>
Copy after login

2) Read a session

session; //读取一个Session $session->get('smister_name); ?>
Copy after login

3) Delete Session

session; //删除一个session $session->remove(‘smister_name’); //删除所有session $session->removeAll(); ?>
Copy after login

The above is the detailed content of How to use yii2 session. For more information, please follow other related articles on 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
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!