I have written an authentication class controller containing a method to check login status of user, and redirect him to login page if he/she is not logged in.
I need to call this function from other controller methods to authenticate the user. What is a good way to do that?
Take that method out of that controller.
Assuming you have a User model, that is a great place to put it if it is authenticating a user and logging them in.
Other places that you may put repeatable code is in helpers (static functions) and libraries (classes).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With