[eluser]Starovich[/eluser]
Hello!
I am currently trying to make a front-end for a CMS system. (The admin panel uses old legacy code for now, this is only for the parts presented to the regular visitors.)
I started out easy by making a controller called "view" and implementing a function called "page", I would then call /view/page/<pagename> to visit a page. the "page" controller would fetch the content from a db, build any additional resources (such as a dynamic menu, for which I placed the build code in a method outside the class, but in the same file.) and send it to a view.
After that I began building additional CMS modules as methods inside the same controller. So I would have for example: "/view/marketplace" or "/view/calendar".
This quickly became unmanageable. I recently wrote a small library in CI and thought about how I perhaps could put the view code in a library instead of having everything in the same controller. Right now I have the following possible solutions:
1.) Make the "view" code into a library, this library would be loaded from any controllers that needed to utilise it, I could then make a marketplace.php controller and simply load the "view" library. Outputting a page would be done by the library, and not the actual controller the user accesses. I'm unsure how CI feels about this.
2.) As suggested by a friend, I could implement a superclass called "Viewable". This class would contain necessary methods and would extend CI's "Controller" class, just like a regular controller, only it would not show anything by itself. Any actual controllers utilising it would extend it. So something like: "class Marketplace extends Viewable" and then Marketplace would have access to all the page-building methods.
3.) Just doing what I'm doing and end up with a 4000 lines long "view" controller.
4.) Your magical solution, which will solve all my problems.
I am fairly new to CI, although I have been coding OOP in various languages.
Thank you for any assistance!