So far, I create one controller for a site section with a method for each page – most are static pages, not requiring much logic or a model.
But where some of those pages are complex in functionality and need their own model, do I need to break them off into their own controllers? or is there a way to keep them in the one controller and load the model per method… probably the wrong thing to do
Totally agree with jondavidjohn’s answer. I suggest just doing what works for you for now, and don’t worry too much about overhead or doing the “correct” thing. You’ll shortly realize what you need to do and how to be organized, and as far as overhead – Codeigniter is pretty lean, don’t worry about optimization at this point – just get everything to work the way you want.
Take your first Codeigniter project and make it the best you can, but just consider it a throw-away app. Each time you work with it you’ll learn more about how to use it, and especially if you keep reading and asking questions.
To answer your literal question: No, there’s nothing wrong with loading the model per method. In fact, it can be “better” than loading in the
__constructof your Controller, because it ensures you only load exactly what you need. So don’t worry about it.There’s nothing wrong with this, but to make things easier, you can use the same method for each of your static pages, and keep your urls the same. Something like this:
This would map the url
/page/my_first_pageto the Page controller and callindex()with the argumentmy_first_page. Then you can use this for all your static pages without dynamic data. You can take this a lot further, but it’s an example of one option you can choose to avoid writing a new method for every static page.