CodeIgniter Forums

Full Version: Using Classes in Helper files?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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?

El Forum

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

El Forum

[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!

El Forum

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