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

responseRedirect redirectParams

#1
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!
 

Myke623

Active member
#3
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
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 :)