public static function getByCode($code) { if (!array_key_exists($code, static::$sites)) { static::$sites[$code] = static::find()->where(['code' => (string) $code])->active()->one(); } return static::$sites[$code]; }
/** * @return CmsSite */ public function getSite() { //return $this->hasOne(CmsSite::className(), ['code' => 'site_code']); return CmsSite::getByCode($this->site_code); }