CodeIgniter Forums
Controllers per page? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Controllers per page? (/showthread.php?tid=50712)



Controllers per page? - El Forum - 04-05-2012

[eluser]jrock2004[/eluser]
So, I am working on my first site using CodeIgniter and I have created one controller and have created function for each page. Is this the process or should I be making a controller for each page? Thanks


Controllers per page? - El Forum - 04-05-2012

[eluser]Naveed Hasan[/eluser]
It really depends upon how you are planning your website. This example could make it clear:

A company has a website with the following pages: Home, About Us, Products, Contact.

Of these, Products may have more sub-pages associated with it for displaying information about individual products. Depending on your Data Model, each product may be identified by an ID/number which corresponds to the ID of the product as stored in your database.

So, you have four controllers: Home, About Us, Products and Contact

In Products you have a function index() like all other controllers for serving the following URL request:

yourwebsite.com/products

You also have another function get_list() (or anything like that) in your products controller, to fetch the product with the following URL:

yourwebsite.com/products/get_list/3
(product_ID = 3)

Please try to read thoroughly:
http://ellislab.com/codeigniter/user-guide/general/controllers.html


Controllers per page? - El Forum - 04-06-2012

[eluser]jrock2004[/eluser]
That makes sense to break up the controllers for menu areas. I do have a lot of pages and it would seem to keep them grouped that way. Thanks for the input.


[quote author="Naveed Hasan" date="1333658481"]It really depends upon how you are planning your website. This example could make it clear:

A company has a website with the following pages: Home, About Us, Products, Contact.

Of these, Products may have more sub-pages associated with it for displaying information about individual products. Depending on your Data Model, each product may be identified by an ID/number which corresponds to the ID of the product as stored in your database.

So, you have four controllers: Home, About Us, Products and Contact

In Products you have a function index() like all other controllers for serving the following URL request:

yourwebsite.com/products

You also have another function get_list() (or anything like that) in your products controller, to fetch the product with the following URL:

yourwebsite.com/products/get_list/3
(product_ID = 3)

Please try to read thoroughly:
http://ellislab.com/codeigniter/user-guide/general/controllers.html[/quote]


Controllers per page? - El Forum - 04-06-2012

[eluser]theshiftexchange[/eluser]
[quote author="jrock2004" date="1333628289"]So, I am working on my first site using CodeIgniter and I have created one controller and have created function for each page. Is this the process or should I be making a controller for each page? Thanks[/quote]


You should generally do a controller for each 'section'/'logic'/'function' of your website.

i.e. A controller for the admin section, a controller for bookings, a controller for payments, a controller for orders.

Each of these controllers would have 1->Many views, depending on what you do.

Making a controller simply for the sake of having one per view would generally be incorrect, but at the end of the day it is really up to you.

More reading:
http://ellislab.com/codeigniter/user-guide/overview/mvc.html
http://ellislab.com/codeigniter/user-guide/general/controllers.html




Controllers per page? - El Forum - 04-06-2012

[eluser]jrock2004[/eluser]
http://greenvalleyhs.org

I am rebuilding that site. So I am going to create a controller for each menu group. I like that idea. Thanks for the help