Welcome Guest, Not a member yet? Register   Sign In
Where do I stick it? (be nice now)
#4

[eluser]Unknown[/eluser]
To follow up and provide some guidance to others, here's what I've done so far that has worked pretty well:
1. included the new library in my controller like this: $this->load->library('my_library');
2. call functions from the controller as usual: $this->my_library->formatURL($params)
3. call back to the model from the library as follow:
Code:
//this is a class level variable, declared just under the class declaration
•  var $CI;
//called from the constructor
•  $this->CI = get_instance();  
//called from the constructor
•  $this->CI->load->model('myinfo_model');
//called from any function
•  $myinfo=$this->CI->myinfo_model->get_myinfo($cat_id);

Now, I can reuse this library's functions in various controllers instead of duplicating the functions. By separating my functions into libraries like this, my controllers can have actions that contain little code themselves, but rather call to the libraries. Not necessarily the simplest approach, but cleaner and more flexible, which is what I understand to be the power of the MVC approach.

Any feedback or suggestions?


Messages In This Thread
Where do I stick it? (be nice now) - by El Forum - 01-20-2010, 08:44 PM
Where do I stick it? (be nice now) - by El Forum - 01-20-2010, 09:15 PM
Where do I stick it? (be nice now) - by El Forum - 01-20-2010, 09:28 PM
Where do I stick it? (be nice now) - by El Forum - 02-09-2010, 08:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB