views:

29

answers:

2

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!

A: 

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.

Sarfraz
A: 

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