Yes you can do it. But this points to problems in your architecture. This is bad practice when the controller contains complex logic.
Maybe you can move the general part of the code into the model and call it in the controllers as a method? Or name $this->redirect()
instead Yii::$app->runAction()
? Try to avoid tight coupling between modules.
:
, . . :
class SampleController extends Controller {
public function actionMyAction() {
return $result;
}
}
class SampleRestController extends Controller {
public function actionMyRestAction() {
return \Yii::$app()->runAction("sample/my-action");
}
}
:
class MyModel {
public function generateResult() {
return $result;
}
}
class SampleController extends Controller {
public function actionMyAction() {
return (new MyModel)->generateResult();
}
}
class SampleRestController extends Controller {
public function actionMyRestAction() {
return (new MyModel)->generateResult();
}
}
MyModel::generateResult()
, . runAction()
.
, runAction()
. .