Jump to:

23483 Posts in 18976 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Set Email::setAdminEmail from SiteConfig?

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

Page: 1
Go to End
Author Topic: 456 Views
  • MarijnKampf
    Community Member
    164 Posts

    Set Email::setAdminEmail from SiteConfig? Link to this post

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

  • martimiz
    Forum Moderator
    1086 Posts

    Re: Set Email::setAdminEmail from SiteConfig? Link to this post

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

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.