protected function getLanguages() { $languages = DctLanguage::find()->select(['dct_language_id as id', 'name', 'locale'])->asArray()->all(); foreach ($languages as $lang) { $langList[$lang['id']] = $lang['name']; } return $languages; }
public function getLangUrl() { if ($this->_lang_url === null) { $this->_lang_url = $this->getUrl(); $url_list = explode('/', $this->_lang_url); $lang_url = isset($url_list[1]) ? $url_list[1] : null; DctLanguage::setCurrent($lang_url); if ($lang_url !== null && $lang_url === DctLanguage::getCurrent()->url && strpos($this->_lang_url, DctLanguage::getCurrent()->url) === 1) { $this->_lang_url = substr($this->_lang_url, strlen(DctLanguage::getCurrent()->url) + 1); } } return $this->_lang_url; }
public function createUrl($params) { if (isset($params['lang'])) { //Если указан идентификатор языка, то делаем попытку найти язык в БД, //иначе работаем с языком по умолчанию $lang = DctLanguage::findOne($params['lang']); if ($lang === null) { $lang = DctLanguage::getDefaultLang(); } unset($params['lang']); } else { //Если не указан параметр языка, то работаем с текущим языком $lang = DctLanguage::getCurrent(); } //Получаем сформированный URL(без префикса идентификатора языка) $url = parent::createUrl($params); //Добавляем к URL префикс - буквенный идентификатор языка if ($url == '/') { return '/' . $lang->url; } else { return '/' . $lang->url . $url; } }
/** * Finds the DctLanguage model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return DctLanguage the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = DctLanguage::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function run() { return $this->render('lang/view', ['current' => DctLanguage::getCurrent(), 'langs' => DctLanguage::find()->where(['enable' => 1])->all()]); }
/** * @return \yii\db\ActiveQuery */ public function getDctLanguage() { return $this->hasOne(DctLanguage::className(), ['dct_language_id' => 'dct_language_id']); }
static function getLangByUrl($url = null) { if ($url === null) { return null; } else { $language = DctLanguage::find()->where('url = :url', [':url' => $url])->one(); if ($language === null) { return null; } else { return $language; } } }