Skip to content

Commit 49a56da

Browse files
authored
docs: Notes about switching types in session (#9508)
* docs: Note about switching types in session * docs: Apply suggestion * docs:Grammar fix
1 parent 73718f4 commit 49a56da

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

user_guide_src/source/libraries/sessions.rst

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

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

347+
Changing the Session Key Type
348+
=============================
349+
350+
Since session data values like Flashdata and Tempdata are differentiated only by internal flags, you can change a value's type without rewriting its data.
351+
352+
.. literalinclude:: sessions/045.php
353+
347354
Closing a Session
348355
=================
349356

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 successful!');
4+
5+
/*
6+
* Get flash value 'Operation successful!' in another controller.
7+
*
8+
* echo session()->getFlashdata('alerts');
9+
*/
10+
11+
// You can switch the session key type from Flashdata to Tempdata like this:
12+
session()->markAsTempdata('alerts');
13+
14+
// Or simply rewrite it directly
15+
session()->setTempdata('alerts', 'Operation successful!');
16+
17+
/*
18+
* Get temp value 'Operation successful!' 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)