nguyendh  
            (Duynguyen0511)
           
           
          
              
                October 26, 2017, 10:07pm
               
               
          1 
           
         
        
          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?
         
         
           
        
            
            
            
         
         
             
             
          
       
      
        
          
          
            jacmoe  
            (Jacob Moena)
           
           
          
              
                October 27, 2017,  1:29am
               
               
          2 
           
         
        
          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?
         
         
        
            
            
            
         
         
             
             
          
       
      
        
          
          
            alirz23  
            (Ali Raza)
           
           
          
              
                October 27, 2017,  5:31pm
               
               
          3 
           
         
        
          behavior seems like better option, in case you want some of your controllers to be excluded.
         
         
        
            
            
            
         
         
             
             
          
       
      
        
          
          
            nguyendh  
            (Duynguyen0511)
           
           
          
              
                October 27, 2017,  9:47pm
               
               
          4 
           
         
        
          i am not sure how to implement behavior. Any sample code?
thanks
         
         
        
            
            
            
         
         
             
             
          
       
      
        
          
          
            uldisn  
            (Uldis Nelsons)
           
           
          
              
                October 28, 2017,  6:18am
               
               
          5 
           
         
        
          Here is solution, how forward definet get parameter:
My be it help you.
         
         
        
            
            
            
         
         
             
             
          
       
      
        
          
          
            nguyendh  
            (Duynguyen0511)
           
           
          
              
                October 30, 2017,  8:36pm
               
               
          6 
           
         
        
          
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.
         
         
        
            
            
            
         
         
             
             
          
       
      
        
          
          
            jacmoe  
            (Jacob Moena)
           
           
          
              
                October 30, 2017,  8:58pm
               
               
          7 
           
         
        
          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.
         
         
        
            
            
            
         
         
             
             
          
       
      
        
          
          
            jacmoe  
            (Jacob Moena)
           
           
          
              
                October 30, 2017,  9:06pm
               
               
          8 
           
         
        
         
        
            
            
            
         
         
             
             
          
       
      
        
          
          
            nguyendh  
            (Duynguyen0511)
           
           
          
              
                October 31, 2017,  6:20pm
               
               
          9 
           
         
        
          I give it a try. Thank you