I'm trying to set the admin email from an entry in the SiteConfig (SilverStripe 3.0). However, the siteconfig class can't be initiated in the _config.php and gives Fatal error: Call to a member function hasField() on a non-object in \framework\model\DataObject.php on line 195. Is there a way to set the admin email using a SiteConfig value?
mysite/_config.php
Object::add_extension('SiteConfig', 'MySiteConfig');
// The following fails with Fatal error.
$config = SiteConfig::current_site_config( );
Email::setAdminEmail($config->AdminEmail);
MySiteConfig.php
<?php
class MySiteConfig extends DataExtension {
static $db = array(
"AdminEmail" => "Text"
);
public function updateCMSFields(FieldList $fields) {
$fields->addFieldToTab('Root.Main', new EmailField("AdminEmail", "Admin email address (from address used for forms etc.)"));
}
}