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, Ed, biapar, Willr, Ingo, swaiba

Set Email::setAdminEmail from SiteConfig?

Go to End

2 Posts   1723 Views


Community Member, 176 Posts

26 September 2013 at 8:00pm

Edited: 26/09/2013 8:01pm

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?


Object::add_extension('SiteConfig', 'MySiteConfig');

// The following fails with Fatal error.

$config = SiteConfig::current_site_config( );


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.)")); 


Forum Moderator, 1391 Posts

28 September 2013 at 5:06am

I don't think there is any way to get to the values stored in database from within _Config.php, so it cannot be set that way at that stage... So the only way that comes to mind at this moment is letting SiteConfig write it to file on save if it changes, and then including that file in your _Config.php. Doable - but I hope someone can come up with a better way...