A
A
Andrey2020-01-30 00:08:23
Yii
Andrey, 2020-01-30 00:08:23

Correct organization of the call structure from the controller?

Kind. Again, I'm tormented by children's questions. Guys, tell me how to properly organize such a construction of calls?
In a nutshell. The Action is given a parameter, and then it is sorted out according to the case.
But apparently, this is possible somehow simply and possibly not correctly.
How would "correctly" knowledgeable people do it?

public function actionIndex( $task = null ){

    switch ( $task ) {
      case 'settings':      return $this->render('index', []); break;
      case 'showallpages':  return $this->render('pagelist', []); break;
      case 'editpage':
        $model = new Page( Yii::$app->request->get('pageId') );
        return $this->render( 'editPage', [ 'model' => $model ] );
      break;
      case 'savepage':
        return 'SAVED !!!!!'; 
      break;

      default: return $this->render( 'index', [] ); break;
    }
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2020-01-30
@skobanev

Remove the switch and do 4 actions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question