[eluser]Mirage[/eluser]
HI -
First of all there is generally nothing wrong with making several controllers even if they do share the same logic. The idea is to build your application in a modular way so that it is manageable and extendable/scaleable. If you pack things into a single controller you are removing modularity and before you know it you'll start coding exceptions in your 'common' controller and you're right back where you started before using an MVC framework.
Having said that, you probably don't want to write a controller for every 'page' in your site. Keep in mind that MVC is a great approach for writing web 'applications', not necessarily web 'pages' or even 'sites' in the traditional sense. So how can you combine the two? There numerous approaches - but if you're just starting, this would help compact things a bit:
Instead of writing a controller with index method for each static page, write one controller with a method for each page. E.g.
Code:
class StaticPage extends Controller {
function index() {
// this is the home page
}
function contact () {
// contact page
}
function projects () {
// projects page
}
}
To map your URLs to this controller, modify your router config:
Code:
// routes.php
$route['default_controller'] = "StaticPage";
$route['(contact|projects)(.*)']='staticpage$1';
There you have it. All in one controller separated by method. You could further optimize this by creating a private method to render that static page and taking that out of your methods:
Code:
// static page controller
function _render($top_data, $content_data, $bottom_data) {
$this->load->view('top',$top_data);
$this->load->view('content', $content_data));
$this->load->view('bottom', $bottom_data);
}
HTH,
-m