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.

General Questions

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

getting variable from another class


Reply

3 Posts   1322 Views

Avatar
grilldan

25 February 2009 at 11:02am (Last edited: 25 February 2009 11:57am), Community Member, 135 Posts

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

GalleryUpload.php

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"?

Avatar
Hamish

25 February 2009 at 12:14pm Community Member, 712 Posts

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

Avatar
grilldan

25 February 2009 at 1:21pm (Last edited: 25 February 2009 1:39pm), Community Member, 135 Posts

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

*edit*
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.

*edit*
Sessions worked :D