Login | Forgot password | Register

X

What is OpenID?

OpenID is an Internet-wide identity system that allows you to sign in to many websites with a single account.

With OpenID, your ID becomes a URL (e.g. http://username.myopenid.com/). You can get a free OpenID for example from myopenid.com.

For more information visit the official OpenID site.

Jump to:

8500 Posts in 2212 Topics by 1195 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.

Page: 1
Go to End
Author Topic: getting variable from another class 602 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
    608 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

    602 Views
Page: 1
Go to Top

Currently Online: There is nobody online.

Welcome to our latest member: U

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

Comments on this website? Please give feedback.