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

[eluser]NeoGeneration[/eluser]
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.
#2

[eluser]boltsabre[/eluser]
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.
#3

[eluser]NeoGeneration[/eluser]
So I should create a helper? This can access libraries and models?
#4

[eluser]boltsabre[/eluser]
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.
#5

[eluser]NeoGeneration[/eluser]
Thanks a lot! will try that. Smile




Theme © iAndrew 2016 - Forum software by © MyBB