Jump to:

23361 Posts in 18124 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » global Vars

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: 411 Views
  • Futureweb
    Avatar
    Community Member
    232 Posts

    global Vars Link to this post

    Hi,

    using htaccess I'm adding a parameter to the URL, which gives a different reference depending what subdomain the user is viewing

    eg,
    member1.mysite.com goes to mysite.com?ref=member1
    member2.mysite.com goes to mysite.com?ref=member2

    SS then presents slightly different info depending on the 'ref' code.

    At present, each time I want to use the ref code, I'm getting the info form the url, checking againts a database table, and getting the user info.

    I would like to get the data once, (maybe in the init function) and then set things like user ID, name etc as global vars.

    If i set the global var in the init function, and try access it in another function, i'm getting swathes of errors. I could maybe set as a session - this could work, but i'm thinking there must be a var of doing this as a global var....

    any ideas?

  • swaiba
    Avatar
    Forum Moderator
    1784 Posts

    Re: global Vars Link to this post

    I'd probably drop the .htaccess stuff and just parse the domain within silverstripe (in the page init method) and lookup the relevant member there. Instead of a global var I'd put the id into the session - but really if you make a nice succinct functino to parse the domain then whenever you want the informatino you coudl just call that instead of session / global var.

  • Futureweb
    Avatar
    Community Member
    232 Posts

    Re: global Vars Link to this post

    Hi Barry,

    Getting SS to parse the domain makes sense. For some reason hadn't thought about that.

    This is now a different issue, but how would one define a function in the page.php file that I could call in the other pages? It's probably a simple issue but I didn't get this to work...

    Cheers

    Jon

  • swaiba
    Avatar
    Forum Moderator
    1784 Posts

    Re: global Vars Link to this post

    make it a public static function

    411 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.