0

Almost in all function in most of my controller i have to see to same things. i.e

1.Check if logged in. 2.Check the privilege.

I know how to do it. But what is the best way, so that i don't have to re-write the same code everywhere? Is it to make a helper or something? I'm a bit new to codeigniter, all i know is basic php!

esafwan
  • 16,014
  • 31
  • 104
  • 160

2 Answers2

0

You may find these links useful:

What Code Igniter authentication library is best?
Authentication with CodeIgniter

You might want to actually create a helper class for user handling to avoid repetitive code if you want.

Community
  • 1
  • 1
Sarfraz
  • 367,681
  • 72
  • 526
  • 573
0

If all the methods in your controller need the same code, you can put that authentification code in the constructor.

Otherwise, creating a helper is probably the best way, but you'll still have to repeat the function in each method subject to authentification.

jfoucher
  • 2,235
  • 2
  • 21
  • 29