-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Flashdata does not work properly #9505
Comments
There is no issue - the flashdata code works as intended. Flashdata is designed for traditional request-response cycles and should be set before performing a redirect. If you need something that will work better with htmx, you can check https://github.com/michalsn/codeigniter-htmx-alerts |
The issue with the flashdata type is open: |
Yes, I think I realized the mistake. Flashdata needs to be used for redirect, if toasts are shown immediately, then you need to add a template to the |
What exactly do you have in mind? Can you be more precise? |
CodeIgniter4/system/Session/Session.php Line 621 in c377646
Why is_int() ?
|
This is how we determine the tempdata: https://codeigniter.com/user_guide/libraries/sessions.html#tempdata |
Hmm, flashdata = tempdata? Not obvious and not documented |
No, flashdata and tempdata are different. The user guide clearly explains the distinction between them. Feel free to send a PR if you think something is missing in the docs. |
I can't describe it correctly in English. My sentences in my native language sound different. But example in controller:
Flashdata is overwritten with tempdata. Therefore, the class Home extends Controller
{
public function index(): string
{
// if (isset($_GET['flash'])) {
// session()->setFlashdata('_flash', 'It flash data.');
// }
// if (isset($_GET['temp'])) {
// session()->setTempdata('_temp', 'It temp data.', 60);
// }
if (isset($_GET['mixed'])) {
session()->setFlashdata('_mixed', 'It flash data >> temp data.');
session()->markAsTempdata('_mixed', 60);
}
if (isset($_GET['see'])) {
// var_dump(session()->getFlashdata('_flash')); // It flash data. Once
// var_dump(session()->getTempdata('_temp')); // It temp data. 60 sec
var_dump(session()->getFlashdata('_mixed')); // null
var_dump(session()->getTempdata('_mixed')); // It flash data >> temp data.
}
return view('welcome_message');
}
} |
Please read the user guide carefully: https://codeigniter.com/user_guide/libraries/sessions.html Every aspect is documented - some highlights:
All these have code examples that demonstrate the concept used. Flashdata is ordinary session data, but treated in a special way, just like tempdata. We can't provide an example for every scenario - especially the less likely ones. Everything is working as expected. |
PHP Version
8.4
CodeIgniter4 Version
4.6
CodeIgniter4 Installation Method
Git
Which operating systems have you tested for this bug?
Linux
Which server did you use?
cli-server (PHP built-in webserver)
Database
No response
What happened?
I use HTMX. Let's say there is a navigation bar with XHR loading.
Home | Main | Acme
The pages inside have forms that show flashdata+form as a result:
After the first sending, the session value is:
and I'm showing toasts:
After the second sending, the session value is:
and I'm showing toasts again. But this is incorrect, it should be a one-time use.
Steps to Reproduce
It is difficult to reproduce outside the project. Better ask clarifying questions.
In short, between two requests, flashdata is not cleaned after the first one.
Expected Output
Flashdata should be a one-time use.
Anything else?
I looked at the code, I think there's a mistake. Flash data never has a timestamp (integer), only
new
orold
. It seems that the code was originally copied from tempdata.The text was updated successfully, but these errors were encountered: