StefGuev
StefGuev

Reputation: 649

Silverstripe How to get datas in SiteConfig from subclasses

Actualy, i'm using this code from a extended class.

Example :

class EcommerceEmail extends Email {
...

    $from = SiteConfig::get()->first()->EcommerceDefaultEmail;

...
}

My problem here is the $from variable. It's working, but I don't think this is the best idea.

I have thinked this

$this->SiteConfig()->EcommerceDefaultEmail

Or this

$this->owner->SiteConfig()->EcommerceDefaultEmail

My last two code don't work and I don't know why. Is there another way to get EcommerceDefaultEmail in SiteConfig() from a subclass?

Upvotes: 1

Views: 59

Answers (1)

bummzack
bummzack

Reputation: 5875

You can use SiteConfig::current_site_config(). Eg.

SiteConfig::current_site_config()->EcommerceDefaultEmail

Upvotes: 5

Related Questions