where to put the actions?
Posted 28 December 2009 - 03:54 PM
Let's say I have a master model with controller (e.g. Vehicle) and 2 sub models (Boat and Bike). General data is stored in the Vehicle (like price), special data in the respective sub tables.
As an example I want to create a new boat dataset/model.
Which of the alternatives would be the best choice?
a) I call the actionCreate in the vehicle controller handing over a variable type=boat. actionCreate then switches to the appropriate lines of code within the actionCreate.
b) I call the actionCreateBoat in the vehicle controller. So for every type of vehicle and for every type of action I would have a dedicated action in the main controller.
c) I somehow extend the vehicle controller with a boat specific controller that contains a create action. So, I would call something like boat/create. As a result I would have a (sub)controller for every type of vehicle (approx. 15).
d) the above options seem to me contradictory to the 'fat model, skinny controller' rule. Perhaps it's something like alternative a), but with functionality moved to the model.
e) none of them.
Posted 02 January 2010 - 05:11 PM
This would be a good option. This way you can enter your url with the appropriate variables directly in your browser. You could also have your actionCreate display a small view where you select the type of vehicle from a listbox. This view then redirects to the actual create-view with the type passed in the url.
This is a possible option, too. This would be an option if you want to create a menu with every available vehicle type listed in it.
You would only want to do this if the different types of models have many differences (next to the similarities).
By the time you'd go this way your little site won't be that little anymore.
alternative a) has no (implicit) functionality specified. It just passes different data (the type) from the model to the view and back again.
Posted 03 January 2010 - 05:25 AM
I think I will take option b. This way it is possible to easily move the whole logic for each type to a separate controller at some point in time if the main controller gets overloaded.