1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

responseRedirect redirectParams

Discussion in 'XenForo Development Discussions' started by Rayman, Oct 20, 2014.

  1. Rayman

    Rayman Member

    Hi,

    I have setup a custom route/page, which works fine. In the page I have a form which later runs actionCustom upon submit (it does this and redirects successfully). However, I would like to be able to use the redirectParams (in this case: $test variable) in the actionCustomList.

    Code:
      public function actionIndex()
      {
         $hello = 'hello';
         $viewParams = array('hello' => $hello);
      return $this->responseView('MyCustomFolder_MyAddonName_ViewPublic_MyFileName', 'mycustomfolder_myaddonname_index',$viewParams);
      }
    
    
    public function actionCustom(){
    $test = 'goodbye';
    
    return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS,
             XenForo_Link::buildPublicLink('mycustomroute/custom/list',$test),
             new XenForo_Phrase('Done!')
    );
    
    }
    
    public function actionCustomList()
      {
    // actionCustom will redirect to this action, how can I use the $test variable here??
    // currently it returns $test is an undefined variable.
         $viewParams = array('test' => $test);
      return $this->responseView('MyCustomFolder_MyAddonName_ViewPublic_MyFileName', 'mycustomfolder_myaddonname_index_list',$viewParams);
      }
    
    I would appreciate any help on how I can use the redirectParams.

    Many thanks in-advance!
     
  2. Rayman

    Rayman Member

    Anybody? :(
     
  3. Myke623

    Myke623 Active Member

    Firstly, in actionCustom() you're not passing the parameters correctly. They need to be the third parameter in buildPublicLink() and in array of name/value pair format. So I'd change it to:

    Code:
    public function actionCustom()
    {
        $test = 'goodbye';
    
        return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS,
                XenForo_Link::buildPublicLink('mycustomroute/custom/list', , array('test' => $test)),
                new XenForo_Phrase('Done!')
        );
    }
    This will result in the redirected link ending in mycustomroute/custom/list?test=goodbye. Then, to read this input variable in actionCustomList(), change it as follows:

    Code:
    public function actionCustomList()
    {
    
        $test = $this->_input->filterSingle('test', XenForo_Input::STRING);
    
        $viewParams = array('test' => $test);
    
        return $this->responseView('MyCustomFolder_MyAddonName_ViewPublic_MyFileName', 'mycustomfolder_myaddonname_index_list',$viewParams);
    }
    This will hopefully get test='goodbye' into your mycustomfolder_myaddonname_index_list template.

    I say "hopefully" because I'm currently away from my development environment, so let us know if this ends up working for you.
     
  4. Rayman

    Rayman Member

    Thanks for your reply! It works great, but I had to add the $test as the second parameter.

    Code:
    XenForo_Link::buildPublicLink('mycustomroute/custom/list', $test, array('test' => $test)),
    Thanks a lot for your help, I had no idea there was a third :)
     
    Myke623 likes this.

Share This Page