-1

I'm quite worried with the current way I structure actions in my controllers.

I'm not sure which is the more adopted method for implementing actions that show different things for different users based on their type.

For example: Creating a Model when User is Type 1 uses the same action but passes more parameters to the view than User Type 2. Creating a Model when User is Type 2 uses same action but passes less parameters to the view and hence there are if statements in the view to show/hide fields based on the User Type.

Is this a proper way of doing things? If not, can you direct me to some documentation that explains a good structure?

Thanks & appreciate your help.

TechMafioso
  • 135
  • 4
  • 16

1 Answers1

0

A simple but trival way is this you can pass an array (eg $param) and then evaluate the type for do the right thinghs inside your action

public function actionYourAction( $param)
{
    $type = $param['type'];
    switch($param['type']){
        case 'TYPE1' :
           ....
           break;

    }

a more clean solution could be a proper object oriented class method specialization for user object, instantiate the proper user object where you nedd and pass thsi in action call. Inside the actione simply use the object (specilized) method .

ScaisEdge
  • 131,976
  • 10
  • 91
  • 107