21310 Posts in 5739 Topics by 2604 members
| Go to End | ||
| Author | Topic: | 1635 Views |
-
Re: Global $var access

14 January 2009 at 4:00am
I didn't realize this was an editable field in the CMS. Well, supposing you only have one HomePage, this should work.. Let's assume the field you're looking for on your homepage is called "GlobalText".
class Page_Controller extends Content_Controller
{function Text()
{
return singleton('HomePage')->GlobalText;
}
} -
Re: Global $var access

14 January 2009 at 5:38am
Sorry, i tried your code, doesnt work for me. Any further ideas?
-
Re: Global $var access

14 January 2009 at 6:13am
Please post all of your code for HomePage.php, Page.php and the relevant part of Page.ss
-
Re: Global $var access

14 January 2009 at 6:19am
Actually, before you do that, try
DataObject::get_one('HomePage')->GlobalText;
-
Re: Global $var access

14 January 2009 at 6:28am
Ok, here we go
HomePage.php:
class HomePage extends Page {
static $db = array(
'varText' => 'Varchar(25)'
);function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Global', new TextField('varText'), 'Content');
return $fields;
}
}class HomePage_Controller extends Page_Controller {
}Page.php:
class Page extends SiteTree {
static $db = array(
);
}class Page_Controller extends ContentController {
function Text() {
return singleton('HomePage')->varText;
}
}Page.ss
$Text
HF
-
Re: Global $var access

14 January 2009 at 10:28am Last edited: 14 January 2009 10:28am
assuming that you only have one page defined as a 'HomePage', then this should work:
class Page_Controller extends ContentController {
function Text() {
return DataObject::get_one('HomePage')->varText;
}
} -
Re: Global $var access

14 January 2009 at 10:33pm
I took yor code. Works fine now. Thanks Hamish and Uncle for your help.
| 1635 Views | ||
| Go to Top |


