How to create a common controller type? Does it makes sense? |
Hello,
first, thanks for this fine framework. I'll still starting, but feel fine. I've create a controller which can load several pages as parameter. Code: public function view($page = "dashboard") I use a modul to dynamic create an array getNavArray(). This works fine, but I'm unsure how to work on with this. I want to add JSQuery datatables and more to several pages. So I can select here which page to show and load the data I need. But I think this will look awefull and I will loose the overview. I could create one controller for each sections. But than I must add this block to alle controllers. If I change the theme, I must modify all controllers. Can I extend the controller to my own version? Or should I create a library where I call GetPageInfos and GetAllPageViews? Thanks Stefan
Hello,
I've not found anything complete here, but there https://philsturgeon.uk/codeigniter/2010...ng-it-DRY/ Thanks Stefan
Hmmm, when I search our forum for "base controller", I come up with the following on just the first page:
http://forum.codeigniter.com/thread-6391...controller http://forum.codeigniter.com/thread-6347...controller http://forum.codeigniter.com/thread-6319...controller http://forum.codeigniter.com/thread-6315...controller http://forum.codeigniter.com/thread-6278...controller http://forum.codeigniter.com/thread-6277...controller Each seems relevant to your question. The user guide is relevant, though it does not explicitly address the base controller... http://www.codeigniter.com/user_guide/ge...asses.html Lonnie's book would help: http://www.codeigniter.com/user_guide/ge...asses.html And, if you are looking for a concrete example: https://github.com/bcit-ci/codeigniter-website And you already found Phil's excellent article ![]()
You want to call a bunch of view files in a standard way. so it can be appropriate to put those calls in a template.
Here's one way to do it: http://forum.codeigniter.com/thread-6379...#pid326426 very similar example with added example of calling a model for a dynamic header http://stackoverflow.com/questions/34909...4#34911214
You should really consider the use of a template engine. Check the Smarty project. You'll find a lot of tutorials to integrate that with you CI installation
Best regards,
José Postiga Senior Backend Developer |
Welcome Guest, Not a member yet? Register Sign In |