Having started with a basic yiic-generated app (incl. CRUD controller) and tested some nested AR queries I want to add real functionality now. The question is where to put the actions?
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.
[color="#808080"]Happy new year to everyone[/color]
Sorry for bothering you with this newbie question. Nevertheless it would be great if you could give me a hint so I can continue to discover Yii on my own.
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.
thanks, Onman, for your comments. It helped me a lot not to start with something on a completely wrong foundation.
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.