I got a Tank Auth library installed in my Codeigniter package, the problem is that I don’t like how to is_logged_in functions need to be called because it’s simply long and not so friendly, as I need to use:
$this->tank_auth->is_logged_in()
Everytime I want to check if user is logged in…
So is there a way to make it shorter? By saying shorter I mean something like $this->logged();?
I would really appreciate if someone could help me.
Thank you.
Head into the
tank_authlibrary and define a new public function:You can now access it with
$this->tank_auth->logged();If you want to shorten the name of
tank_auth, you’ll have to rename the class and the filename.UPDATE:
The more important question is, why are you calling this so many times that it is becoming an annoyance? You should only have to write it once if your code follows the Don’t Repeat Yourself (DRY) principle.
Have a look at Phil Sturgeon’s blog post entitled Keeping It DRY. He will show you how to write a base controller that all your controllers will inherit from. If you write the login check in the constructor of the base controller, you don’t have to write it in every controller.