CodeIgniter Forums
One method for multiple 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: One method for multiple controllers? (/showthread.php?tid=10024)



One method for multiple controllers? - El Forum - 07-16-2008

[eluser]erik.brannstrom[/eluser]
Hi!

I'm building a site which features some basic community functions, pretty much meaning a simple messaging system. The messaging functionality is up and running, problem is I now want the link to the inbox to reflect wheter or not there are unread messages waiting.

This link is in the header view, which is loaded in every controller. I want it to check for new messages on every page load but I can't figure out how to do that without breaking the MVC model and without having to repeat the same line of code in every controller.

Is a hook at post_controller_constructor a possible solution? I just have a feeling that this is not what is meant by "extending the framwork core".. All suggestions are very much welcome!

Best regards,
Erik Brännström


One method for multiple controllers? - El Forum - 07-16-2008

[eluser]erik.brannstrom[/eluser]
I found this post a few steps below mine: Repeating piece of code. Is creating a subclass to CI_Controller and then extend all my controllers from that subclass the best solution? It seems I will still have to make the same method calls even though the method doesn't have to be redefined. Can this be improved even more perhaps?