Welcome Guest, Not a member yet? Register   Sign In
Do I really need multiple controllers for each and every page?
#1

[eluser]dallen33[/eluser]
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):

http://mywebsite/lawyers
http://mywebsite/practice_areas
http://mywebsite/fees

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:

http://mywebsite/app/lawyers
http://mywebsite/app/practice_areas
http://mywebsite/app/fees
#2

[eluser]umefarooq[/eluser]
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

Code:
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
http://ellislab.com/codeigniter/user-gui...uting.html
#3

[eluser]skunkbad[/eluser]
I think you can either use routes or mod_rewrite to remove app. Oops, somebody beat me to it.
#4

[eluser]dallen33[/eluser]
Very cool. I didn't quite understand the routing, but now I do. Thanks umefarooq!




Theme © iAndrew 2016 - Forum software by © MyBB