Jump to:

23553 Posts in 19380 Topics by 2892 members

General Questions

SilverStripe Forums » General Questions » Passing Variables and redirection

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2023 Views
  • J2-Paul
    Community Member
    51 Posts

    Passing Variables and redirection Link to this post

    Is it possible to write a method that redirects to another page and for that method to also return a variable to the call.

    In the attempt below I am attempting to pass the variable $status back to the page being redirected to.

    I know this could be accomplished with session variables. But I wondering if there is better solution.

    Thanks in advance.


       function doAddStudent($data,$form) {

          // create student data object
          $student = new student();

          // check for matches
          $dupe = DataObject::get('Student',
          //   && `FirstName`='".Convert::raw2sql($student->FirstName)."'"

    //      Debug::show($dupe);
          if (!$dupe) {
                $status='Record Saved';
                $status='Record not saved: Duplicate exists'

  • Willr
    Forum Moderator
    5511 Posts

    Re: Passing Variables and redirection Link to this post

    If you are using the built in form validation you can do $form->addErrorMessage('Message', 'This is an error', 'bad'); before your redirect back which will pass the error message via the Session class.

    Or you can use the Session class directly to save the value, get the value http://doc.silverstripe.org/sessions

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.