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

Global $var access


Go to End
Reply

16 Posts   2018 Views

Avatar
MrHyde

13 January 2009 at 5:08am (Last edited: 14 January 2009 12:43am), Community Member, 23 Posts

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?

Avatar
UncleCheese

13 January 2009 at 5:31am 4085 Posts

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

Avatar
MrHyde

13 January 2009 at 6:20am (Last edited: 13 January 2009 6:40am), Community Member, 23 Posts

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;
}

Avatar
UncleCheese

13 January 2009 at 6:36am 4085 Posts

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

Avatar
MrHyde

13 January 2009 at 6:41am (Last edited: 13 January 2009 6:41am), Community Member, 23 Posts

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

Avatar
MrHyde

13 January 2009 at 11:52pm Community Member, 23 Posts

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?

Avatar
Carbon Crayon

14 January 2009 at 12:06am Community Member, 598 Posts

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

Avatar
MrHyde

14 January 2009 at 12:42am Community Member, 23 Posts

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.

Go to Top