I have controller where I need to access an action from another controller and return data:
rest/controllers/AController
switch (@$_GET['barcodeType']) 
{
    case '1D':
    {  
            //do action Request1 from BController and return data from 
            this controller
    }
    break;
    case '2D':
    {
            //do action Request2 from BController and return data from 
            this controller
    }
    break;
    default:
    return  ['Wrong barcodeType'];
    break; 
}
soap/controllers/BController
public actionRequest1{
    //do something and return data to AController
}
public actionRequest2{
    //do something and return data to AController
}
How can I do this?
You can do this, if you need to reuse another controller's action:
$result = Yii::$app->runAction('b/request1', ['param1' => 'value1', /* ... */]);
But I don't recommend it. I suggest you to move the logic to another component, so both controllers can use it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With