How to get a requested controller id / action id which is not found?

Hello,

My Yii2 app’s 404 request will be redirected to site/error. that works well.

I want to evaluate the requested controller ID and the action ID before rendering the view.

then based on the result i will render error view or redirect to another page together with the requested parameters if anything.

How to achieve that?

Maybe this will help http://www.yiiframework.com/doc-2.0/yii-base-controller.html#beforeAction()-detail

Thank you Bizley.

Your suggestion is to use beforeAction() Method ( probably from Site controller).

It may help.

But how to retrieve the controller ID and action ID were requested originally but does not exist.(404)

Thanks

Second thought - beforeAction is probably invoked too late for your needs. I think that better is to override the errorAction (usually \yii\web\ErrorAction) and there you call for example Yii::$app->getRequest()->getPathInfo() to get the url user entered.

Thank you Bizley.

Your second thought fixed my problem.