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