Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Passing Variables and redirection


Go to End


2 Posts   3227 Views

Avatar
J2-Paul

Community Member, 51 Posts

11 June 2010 at 12:24pm

Edited: 11/06/2010 12:36pm

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();
		$form->saveInto($student);

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

//		Debug::show($dupe);
		if (!$dupe) {
				$student->write();
				$status='Record Saved';
				$this->redirect('..'); 
			}
			else{
				$status='Record not saved: Duplicate exists'
				$this->redirectback(); 
			}
			
    } 

Avatar
Willr

Forum Moderator, 5523 Posts

11 June 2010 at 7:20pm

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