redirect to billing page all the time

I want to redirect a user to billing page if he does not subscribe after a trial. Whenever he goes to different part of the site, he will be always redirected to billing page until he subscribes.

At the moment, I can have the code in every single controller/actions. But it is messy and duplicates everywhere.

Is there an elegant/simple way to do this?

The simplest method would be to create a parent controller so that you only have the code in one place.

Other option is a behavior.

And perhaps events?

behavior seems like better option, in case you want some of your controllers to be excluded.

i am not sure how to implement behavior. Any sample code?

thanks

Here is solution, how forward definet get parameter:

My be it help you.

I don’t understand how this solves my issue.

I want to check if a user is not subscribed, redirect him to billing page. This check must run on all controller/action.

You could use a controller filter, base it on vendor/yiisoft/yii2/filters/AccessControl and then modify it to do what you want it to do.

It’s fairly easy to create your own filters:

http://www.yiiframework.com/doc-2.0/guide-structure-filters.html

I give it a try. Thank you