Filter and Controller - Best practice |
Hi all,
i am new to CI4 and i am trying to migrate my CI3 project to CI4 and my head still has to get used to CI4 a bit and get rid of the old thinking patterns ;-) In CI3, I had separate controllers for the public/member/admin areas and extended the controllers of the individual pages accordingly from one of these controllers. In the member/admin area the session was checked and the current data of the user was fetched from the database. If I have understood this correctly, it is intended in CI4 to check the session using the filters. This also works so far. Where I am still thinking about how to get the user data for the user/admin area. What is the best or the intended way here? Create own controllers (MemberController, AdminController) from the BaseController and then query the data in the initController method? Would be happy about a push in the right direction Cheers Marc
Get user id from session and load user from db. Current user object you can put in global scope or create singleton CurrentUser class
I would recommend looking at the Shield package, it has many features with build-in groups/permissions.
Currenctly using it myself, pretty easy to use and customizable at your own requirements. (12-20-2022, 01:15 AM)mcbookwood Wrote: In CI3, I had separate controllers for the public/member/admin areas and extended the controllers of the individual pages accordingly from one of these controllers. In the member/admin area the session was checked and the current data of the user was fetched from the database. You don't need to use Filters. It is no problem that you have separate controllers and check the session in CI4. If you move the logic to a filter, and if you misconfigure, the filter may be bypassed. |
Welcome Guest, Not a member yet? Register Sign In |