21280 Posts in 5729 Topics by 2600 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 185 Views |
-
SS3 - Accessing SiteConfig values in Widget class

17 September 2012 at 1:10pm
I'm having issues getting hold of values stored in my SiteConfig from within my widget class. I searched around and found people suggesting I should be able to access the config through SiteConfig::current_site_config() but when I try and implement this, I get an error:
Parse error: syntax error, unexpected '(', expecting ',' or ';' in /...../widgets_facebookFeed/FacebookFeedWidget.php on line 3
<?php
class FacebookFeedWidget extends Widget{
static $thisConfig = SiteConfig::current_site_config();
static $title = "";
static $cmsTitle = "Facebook Feed Widget";
static $description = "This widget shows the Facebook feed";static $db = array(
"FacebookURL" => "Text"
);
static $defaults = array(
"FacebookURL" => $thisConfig->FacebookURL
);function getCMSFields(){
return new FieldList(
new TextField("FacebookURL", "Facebook URL")
);
}
function getFacebookURL(){
$output = new ArrayList();
$output->push(
new ArrayData(
array(
"FacebookURL" => $this->URL
)
)
);
return $output;
}
}What am I doing wrong here?
-
Re: SS3 - Accessing SiteConfig values in Widget class

18 September 2012 at 7:46am
The Problem is this line:
static $thisConfig = SiteConfig::current_site_config();
In PHP, it is not possible to initialize a static constant with the result of a function call (i.e. you are not allowed to call a function there). You will have to set the default value in some other way (or at a different point in your code).
| 185 Views | ||
|
Page:
1
|
Go to Top |

