CodeIgniter Forums
Can I use session()->push in a model? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Can I use session()->push in a model? (/showthread.php?tid=88790)



Can I use session()->push in a model? - bgeneto - 11-07-2023

I'm using CodeIgniter 4.4.3 and I would like to know if it is still valid to use session()->push() in a model that extends BaseModel. 

It seems that we can't use session()->get() anymore, but I think that session()->push() is useful if sessions are stored in the database and we need to update a database value that is somehow related to a session. 
Regards.


RE: Can I use session()->push in a model? - JustJohnQ - 11-07-2023

According to the documentation:
https://codeigniter4.github.io/userguide/libraries/sessions.html?highlight=push#pushing-new-value-to-session-data


RE: Can I use session()->push in a model? - bgeneto - 11-08-2023

(11-07-2023, 11:22 AM)JustJohnQ Wrote: According to the documentation:
https://codeigniter4.github.io/userguide/libraries/sessions.html?highlight=push#pushing-new-value-to-session-data
It's strange. I tested using session()->get() in my model, and it returned nothing. I initially thought it might be an upgraded feature or a security measure because using Services in models and libraries isn't recommended. But now I realize that Services still work in models. My apologies for the silly question.