Welcome Guest, Not a member yet? Register   Sign In
Converting an existing app - what to do with my functions?
#1

[eluser]ckeller[/eluser]
I'm in the process of converting an app, and the MVC side is fairly easy. One thing that I'm not sure about though is all my existing functions that I called throughout the app (this is not an OO app).

Can I still access/use those functions in my controller methods or do I have to convert all those functions into a library (or helper file?) and load those into my controller?

Thanks,

Chris
#2

[eluser]kgill[/eluser]
It all depends on what they do and how often you'll use them. First decide where they'll be used from, model or controller? If it's one of those two are the functions used in every model or controller? If that's the case it would probably make more sense to add them to your own MY_ controller or model and extend that. If they're only used in some of the controllers/models then a library or helper might be more appropriate so you can load it only when they're needed. Finally if only one model or controller needs them then put them directly in that file unless you foresee the possibility of the functions being needed by something else in the future.
#3

[eluser]ckeller[/eluser]
Great reply, thanks.

Any thoughts on making the functions be a library or a helper file where they can just be called as is?

If I made them a helper file, then I assume I could just call the functions right away in the controller code, and they'd work. Correct?
#4

[eluser]kgill[/eluser]
Almost correct, you'd have to load the helper first but once that's done then you could call them in your controller and they'd work. For a library you'd be bundling them into an object and accessing them through that. There's an entire discussion to be had on when something should be a library instead of helper but basically if they're just a random collection of functions you need once and a while, make them a helper.
#5

[eluser]ckeller[/eluser]
Thanks. If I wanted to use the CI libraries in those functions, is there a way that I could still use them without creating a new instance of the main CI object? (basically like the example given when creating your own library)

public $CI;

$this->CI =& get_instance();
$this->CI->load->helper('url');
$this->CI->load->library('session');
$this->CI->load->database();




Theme © iAndrew 2016 - Forum software by © MyBB