Yii Framework Forum: where to put the actions? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

where to put the actions? Rate Topic: -----

#1 User is offline   steffen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 14-December 09
  • Location:Reutlingen, DE

Posted 28 December 2009 - 03:54 PM

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.

e) none of them.
0

#2 User is offline   steffen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 14-December 09
  • Location:Reutlingen, DE

Posted 02 January 2010 - 12:08 PM

Happy new year to everyone

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.

Thank you very much in advance.
0

#3 User is offline   Onman 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 175
  • Joined: 26-December 09
  • Location:The Netherlands

Posted 02 January 2010 - 05:11 PM

View Poststeffen, on 28 December 2009 - 03:54 PM, said:

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.

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.

View Poststeffen, on 28 December 2009 - 03:54 PM, said:

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.

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.

View Poststeffen, on 28 December 2009 - 03:54 PM, said:

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).

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.

View Poststeffen, on 28 December 2009 - 03:54 PM, said:

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.

alternative a) has no (implicit) functionality specified. It just passes different data (the type) from the model to the view and back again.

View Poststeffen, on 28 December 2009 - 03:54 PM, said:

e) none of them.

0

#4 User is offline   steffen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 14-December 09
  • Location:Reutlingen, DE

Posted 03 January 2010 - 05:25 AM

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users