Redirect within a function in a controller: how to handle return?

Hello,

in my controller there is a function which is called in nearly every action to check if the user has the right to see the action, if he hasn’t, she should be redirected, otherwise the company is beeing returned. But working with


return $this->redirect(['/other_controller']);

does nothing, because it returns an Response object as company :(




public function check_company($path) {

	if ($condition) {

		if ($second_condition) {				

			return $this->redirect(['other_controller', 'parameter' => $parameter]);				

		} else {

			$company = Company::find()->where(['path' => $path])->one();

			return $company;				

		}

	} else {

		Yii::$app->getSession()->setFlash('danger', 'No Access.');

		return $this->redirect(['/other_controller']);

	}		

}

working with exit or Yii::$app->response->redirect([‘other_controller’]) didn’t work either.

Any ideas? Thanks!

return redirect should happen in the controller action itself.