Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access Controller class in CodeIgniter

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?

like image 439
VarunGupta Avatar asked May 09 '26 19:05

VarunGupta


1 Answers

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).

like image 164
Matthew Rapati Avatar answered May 11 '26 10:05

Matthew Rapati



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!