CodeIgniter Forums
Using Classes in Helper files? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Using Classes in Helper files? (/showthread.php?tid=10451)



Using Classes in Helper files? - El Forum - 07-31-2008

[eluser]Iverson[/eluser]
I'm using CI's database class in my controllers. I have a "is_logged_in" function that I will have to use in every controller/view so I created my own helper file because I don't want to have to copy and paste it over and over again. I check the session footprint against the footprint I put into my database. However, now I have no way of getting to the database or the session data because I can't use the class functions inside a regular function. Ideas? Or am I just missing something?


Using Classes in Helper files? - El Forum - 07-31-2008

[eluser]Yash[/eluser]
Just use model.

Create a function in a model. Check session or do whatever you want. like redirecting to login form if not logged and so on...

Now access this function in controller functions.

I like this way..You can decide your own.


Using Classes in Helper files? - El Forum - 07-31-2008

[eluser]Iverson[/eluser]
You know what? I was wondering if that's what models were for. I've only been using CI for about 2 weeks. I've found MVC to be quite useful. However I've only gotten to play with the V's and C's so far...lol. Thanks!


Using Classes in Helper files? - El Forum - 07-31-2008

[eluser]Yash[/eluser]
Models are very easy to use.Just do one thing read user guide carefully then you will ask less Qs and code more.