Skip to content

Commit 4ba0b04

Browse files
committed
docs: Note about switching types in session
1 parent 73718f4 commit 4ba0b04

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

user_guide_src/source/libraries/sessions.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,15 @@ intend to reuse that same key in the same request, you'd want to use
344344

345345
.. literalinclude:: sessions/036.php
346346

347+
Flag Manipulation
348+
=================
349+
350+
Since the data is stored in the session and the Flashdata/Tempdata methods only manipulates flags, you can change the type for one value.
351+
352+
.. literalinclude:: sessions/045.php
353+
354+
You may never use it, but know that it works.
355+
347356
Closing a Session
348357
=================
349358

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
session()->setFlashdata('alerts', 'Operation success!');
4+
5+
/**
6+
* Get flash value 'Operation success!' in another controller.
7+
*
8+
* echo session()->getFlashdata('alerts');
9+
*/
10+
11+
// Switch flag
12+
session()->markAsTempdata('alerts');
13+
14+
// or rewrite
15+
session()->setTempdata('alerts', 'Operation success!');
16+
17+
/**
18+
* Get temp value 'Operation success!' in another controller.
19+
*
20+
* echo session()->getTempdata('alerts');
21+
*
22+
* But flash value will be empty 'null'.
23+
*
24+
* echo session()->getFlashdata('alerts');
25+
*/

0 commit comments

Comments
 (0)