Welcome Guest, Not a member yet? Register   Sign In
[EASY] Best practice for this (MVC)

Hello there,

I have some functions that connect to a model and to a library. These functions were initially in a controller but now I'm using the same logic in another controller.

I was wondering whats the best practice here to get the code tidy.

I tried to convert my functions to a library or helper but I got lost and I don't know if that is what I should do.

Thanks for that.

Libraries are more for if you need to create a class/object, whereas helpers are just for "function" storage.

So depending on what you're doing, either should be fine for this kind of situation.

So I should create a helper? This can access libraries and models?

Quote:So I should create a helper?
No idea, as I said, it really depends on what you're trying to do. If it's just a function then fine, but if you need to create a class/object then you should do it in a library.
Yes, you can load libraries/models/etc in helpers (and in your own libraries).
But you cannot use $this, it has to be $CI... just google "codeigniter how to load a library in a helper" for more details.

Thanks a lot! will try that. Smile

Theme © iAndrew 2016 - Forum software by © MyBB