• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Do I really need multiple controllers for each and every page?

I built a website that's pretty basic, but I used CodeIgniter as the base incase I needed to add functionality.

Each page has it's own controller so the URL can be clean, like this (I'm using a URL rewrite to hide index.php):


But for each of those pages, I have a controller. I have about 20 of them. It seems like a lot. Am I missing something? Is there a way I can have just one controller while maintaining the clean URLs like above?

I tried having one controller (I named it app), but the problem was I was getting URLs like this:


if these controller are accessing same table to get data then you can have one controller if they are getting different tables then again you can use the same controller but you controller will be little complex

for both case you have to set route to your url in config/routes.php file

create a route

if using index() function
$route['(:any)'] = "app";

using other than index() function specific
$route['(:any)'] = "app/funciton_name";

it will call your lawyers,fees and so on function of app controller
$route['(:any)'] = "app/$1";

check user guide for routing

I think you can either use routes or mod_rewrite to remove app. Oops, somebody beat me to it.

Very cool. I didn't quite understand the routing, but now I do. Thanks umefarooq!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.