Jump to:

23374 Posts in 18175 Topics by 2866 members

General Questions

SilverStripe Forums » General Questions » getting variable from another class

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: 1297 Views
  • grilldan
    Avatar
    Community Member
    135 Posts

    getting variable from another class Link to this post

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

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: getting variable from another class Link to this post

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

  • grilldan
    Avatar
    Community Member
    135 Posts

    Re: getting variable from another class Link to this post

    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

    1297 Views
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.