![]() |
Repeating Code in Controller - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Repeating Code in Controller (/showthread.php?tid=29119) |
Repeating Code in Controller - El Forum - 03-30-2010 [eluser]Unknown[/eluser] Hello all, My problem is I'm finding that I'm repeating my code in the controllers and was wondering if there was a better way of handling it? In the below code I have index and settings_profile functions... within those I have several arrays that do the same thing. For example, I have this being called twice. I tried putting the array in the __construct but that didn't work. Any help would be great. Thanks. Code: $memProfile = $this->account_details_model->get_member_profile(); Code: class App extends Controller { Repeating Code in Controller - El Forum - 03-30-2010 [eluser]frist44[/eluser] Private functions: Code: private function _get_member_profile() { Then call this function from your controller functions. $memProfile = $this->_get_member_profile(); Repeating Code in Controller - El Forum - 03-30-2010 [eluser]InsiteFX[/eluser] Use a MY_Controller it's in the users guide. Enjoy InsiteFX |