Welcome Guest, Not a member yet? Register   Sign In
Confusion about controllers and what I need?
#1

[eluser]Jeff_B[/eluser]
I have a very basic site responsible for only a few pages:

1. Display the login page (conditional)
2. Display the "Orders Page" (index/home)
3. Display the "Products Page"
4. Display the "Users Page"

Then these sub-pages:

1. Display the "Products Edit Page"
2. Display the "Users Edit Page"

I'd like my URI's to look like this:

- example.com/
- example.com/products/
- example.com/products/edit/
- example.com/users/
- example.com/users/edit/

Should I be creating just one controller with several methods (functions) in each?

I guess this is just a basic confusion I have about controllers.
#2

[eluser]jedd[/eluser]
Hi Jeff_B,

I'd be creating two controllers - Users and Products.

(Actually, I'd create User and Product, but I'm hardcore Smile
#3

[eluser]BrianDHall[/eluser]
The idea of having multiple controllers is purely for organizational reasons. I've built large websites with one controller, but what you think will be small has a way of getting very big - and leaves you wishing you'd spent a few extra minutes slicing things up a bit more finely.

Without knowing much more than what is implied with your desired naming structure, I'd do something like this:

1- MY_Controller to control shared functionality, like login functions. Possibly use a Library to hold the auth functionality. Use to embed it right in the controller, but it can help keep the project clean to keep it all in a separate place.

2- Main controller, to control the default way the site looks when someone pulls up example.com. It likely calls upon User model and Products model for various functions, etc.

3- Products controller to handle things that are very specific to products, especially add/edit/delete functionality and so forth.

4- Users controller, just like products controller.

5- Products, User, and Order(?) models.

There is no hard and fast rule about what goes where, but this gives you all the elements and helps to organize things (both in the practice of coding and inside your head). So functions specific to one controller go in the controller, functions specific to controlling/manipulating data goes into certain models, etc
#4

[eluser]Jeff_B[/eluser]
Thanks! Input is much appreciated.




Theme © iAndrew 2016 - Forum software by © MyBB