Jump to:

23376 Posts in 18218 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Global $var access

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 2
Go to End
Author Topic: 1961 Views
  • MrHyde
    Avatar
    Community Member
    23 Posts

    Global $var access Link to this post

    Hi, let me explain my porblem. I#m lookinfg for answers for hours.

    I want a text to show up on my site's footer, so i declared a var $text in code/HomePage.php to make this text editable in the cms. Works so far. I access the var by $text in page.ss.
    But it is just shown if $Layout (in page.ss) is rendered by using HomePage.ss. How do i get global access to these kind of vars?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Global $var access Link to this post

    Just put it in Page.php. That's probably easiest. Everything descends from that, right?

  • MrHyde
    Avatar
    Community Member
    23 Posts

    Re: Global $var access Link to this post

    I put i page.php, but still the same problem as i described above. any more ideas?

    I'm doing this in page.php:

    class Page_Controller extends ContentController {

    function text() {
    return $this->Textfromhomepagephp;
    }

  • UncleCheese
    Avatar
    4085 Posts

    Re: Global $var access Link to this post

    Uhh.... what is your HomePage controller doing in Page.php?!

  • MrHyde
    Avatar
    Community Member
    23 Posts

    Re: Global $var access Link to this post

    Well, just copied the wrong code from clipboard. i corrected my previous post.

  • MrHyde
    Avatar
    Community Member
    23 Posts

    Re: Global $var access Link to this post

    I really need your help this. I'm currently working with this code in

    page.php

    class Page_Controller extends ContentController {

    function text() {
    return DataObject::get_one('HomePage',$var);
    }
    }


    Any ideas?

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Global $var access Link to this post

    return DataObject::get_one('HomePage',$var);

    What are you trying to do with this line? The second argument has to be a filter (something like 'ID = $ID'). Where are you trying to get $var from as I cant see it in your function and your not passing it in....

  • MrHyde
    Avatar
    Community Member
    23 Posts

    Re: Global $var access Link to this post

    Hey aram, i agree that i dont really know what i'm doing there. Would be glad if you could once again read my first post and tell me how to access $var from HomePage.php in Page.php.

    1961 Views
Page: 1 2
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.