How to call a different Controller action withing an other controller action


I have a controller C1 that have action A11 and A12
and a controller C2 that have action A21 and A22
and a controller C3 that have action A31 and A32.

Supposing I have a request being handled by C1-A11. Within it, we decide the appropriate action to handle it, it can be A22 or A32, and after it something need to be done inside A11.

What the best way to make this please ?



you could outsource the actions like for e.g. class UserProfileAction that extends from Action and Controllers are only responsible for calling logic.

Did you have a look into the runAction() function that’s available from Yii::$app?


Thank your for the response. Using runAction result to something like this :

class C1 controller {
  A11Action() {
     $outcome = [];
     $boolean = DoThisFirst();

          $outcome[] = Yii::$app->runAction([C2/A21]);
          $outcome[] = Yii::$app->runAction([C3/A32]);

     $showMe = DoThisAfter($outcome);
     return $this->render('view', [
            'showMe' => $showMe

This would be a solution, but what would be the best practice ?