Home  >  Article  >  PHP Framework  >  How to use yii2 session

How to use yii2 session

(*-*)浩
(*-*)浩Original
2019-11-05 13:43:412822browse

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]);
?>

2) Read a session

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

3) Delete Session

<?php
$session = \Yii::$app->session;
//删除一个session
$session->remove(‘smister_name’);
//删除所有session
$session->removeAll();
?>

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!

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