Common methods for all controllers - 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: Common methods for all controllers (/showthread.php?tid=25493) |
Common methods for all controllers - El Forum - 12-14-2009 [eluser]owidiuszek[/eluser] Hello, What is the best way to make few methods available to all controllers? for example some result view: Code: function showResult($text, $state) $this->showResult('aaa','bbb'); (or similar) without pasting this code inside each controller. Should I create for example maincontroller and then extend all others basing on it? Or maybe usage of library or helper would be better? Common methods for all controllers - El Forum - 12-14-2009 [eluser]umefarooq[/eluser] if your loading view for your result you can use widget plugin for your problem have look on the link http://ellislab.com/forums/viewthread/109584/ Common methods for all controllers - El Forum - 12-14-2009 [eluser]mattpointblank[/eluser] This is what libraries and helpers are for. If it's just a small function then a helper seems best to me. Common methods for all controllers - El Forum - 12-14-2009 [eluser]davidbehler[/eluser] Quote:Should I create for example maincontroller and then extend all others basing on it? That's exactly what I would do. No need for a helper/library here. Common methods for all controllers - El Forum - 12-14-2009 [eluser]Boris Strahija[/eluser] You could use MY_Controller http://ellislab.com/codeigniter/user-guide/general/core_classes.html Common methods for all controllers - El Forum - 12-14-2009 [eluser]owidiuszek[/eluser] MY_Controller works nicely and smoothly. But if it is the same idea as making own controller and extending others on it - what is the point of making it as a library? Anyway Thanks |