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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

getting variable from another class

Go to End

3 Posts   1595 Views


Community Member, 135 Posts

25 February 2009 at 11:02am

Edited: 25/02/2009 11:57am

I need to get a variable from another class in the same file, for a widget I am making.


class GalleryUpload extends Widget {
	static $db = array(
				"GalleryName" => "varchar", //gallery name
				"Location" => "varchar", //location of folder to upload files to
				"Redirect" => "varchar" //landing page after user uploads image
class GalleryUpload_Controller extends Controller {
	function doForm($data, $form) {
	   $file = new File();
	   $file->loadUploaded($_FILES['FileTypeID'], "/galleries/" . $this->Location ); // HERE
	   // Redirect to a page thanking people for registering
	   Director::redirect( $this->Redirect ); // HERE


On the lines that say "//HERE" are the variables I need from above. I have tried several things, just to see if it would work, but no luck.

How could I get the variables from "class GalleryUpload" into "class GalleryUpload_Controller"?


Community Member, 712 Posts

25 February 2009 at 12:14pm

Just use $this-> GalleryName or whatever. Variables from the dataobject are available from it's controller.


Community Member, 135 Posts

25 February 2009 at 1:21pm

Edited: 25/02/2009 1:39pm

That was the first thing I tried, but $this->Anything will always be blank. Is there another way?

It is a submit form, so I am going to try session variables to set $this->Location, and $this->Redirect, and see how that works out. I would still like some better ideas though.

Sessions worked :D