Jump to:

23014 Posts in 11873 Topics by 2830 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: 297 Views
  • MarijnKampf
    Avatar
    Community Member
    161 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?

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

  • martimiz
    Avatar
    Forum Moderator
    1038 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...

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