Home > PHP Framework > YII > body text

How to use yii2 session

(*-*)浩
Release: 2019-11-05 13:43:41
Original
2796 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)

<?php
$session = \Yii::$app->session;
$session->set(&#39;smister_name&#39; , &#39;myname&#39;);
$session->set(&#39;smister_array&#39; ,[1,2,3]);
?>
Copy after login

2) Read a session

<?php
$session = \Yii::$app->session;
//读取一个Session
$session->get(&#39;smister_name);
?>
Copy after login

3) Delete Session

<?php
$session = \Yii::$app->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
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!