當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ActiveRecord::getTranslation方法代碼示例

本文整理匯總了PHP中yii\db\ActiveRecord::getTranslation方法的典型用法代碼示例。如果您正苦於以下問題:PHP ActiveRecord::getTranslation方法的具體用法?PHP ActiveRecord::getTranslation怎麽用?PHP ActiveRecord::getTranslation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yii\db\ActiveRecord的用法示例。


在下文中一共展示了ActiveRecord::getTranslation方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: run

 /**
  * @inheritdoc
  */
 public function run()
 {
     $items = [];
     /** @var \DevGroup\Multilingual\Multilingual $multilingual */
     $multilingual = Yii::$app->get('multilingual');
     $languages = $multilingual->getAllLanguages();
     foreach ($languages as $index => $language) {
         $flag = $language->iso_639_1 === 'en' ? 'gb' : $language->iso_639_1;
         $items[] = ['label' => '<span class="flag-icon flag-icon-' . $flag . '"></span> ' . $language->name, 'active' => $index === 0, 'content' => $this->renderFile($this->childView, ['model' => $this->model->getTranslation($language->id), 'form' => $this->form, 'language' => $language, 'language_id' => $language->id, 'attributePrefix' => "[{$language->id}]"])];
     }
     FlagIconAsset::register($this->view);
     $items = ArrayHelper::merge($items, $this->additionalTabs);
     return "<div class=\"nav-tabs-custom {$this->tagClass}\">" . Tabs::widget(['items' => $items, 'options' => $this->options, 'encodeLabels' => false]) . $this->footer . '</div>';
 }
開發者ID:duvanskiy,項目名稱:yii2-multilingual,代碼行數:17,代碼來源:MultilingualFormTabs.php

示例2: saveData

 /**
  * @param array $data
  */
 private function saveData(array $data)
 {
     foreach ($this->getLanguages() as $locale => $language) {
         /** @var ActiveRecord $translation */
         $translation = $this->owner->getTranslation($locale)->one();
         if ($translation === null) {
             $translation = new $this->translationModelName();
             $translation->{$this->translationOwnerField} = $this->owner->{$this->ownerPrimaryKey};
             $translation->{$this->languageField} = $language->id;
         }
         if (isset($data[$locale])) {
             $translation->setAttributes($data[$locale]);
         }
         if (!$translation->save()) {
             $this->owner->addError($locale, $translation->getErrors());
         }
     }
 }
開發者ID:gbksoft,項目名稱:yii2-multilingual,代碼行數:21,代碼來源:Multilingual.php

示例3: loadModels

 /**
  * @param \yii\db\ActiveRecord $model
  *
  * @return bool
  */
 public function loadModels($model)
 {
     $loaded = true;
     if ($model instanceof \common\components\model\Translateable) {
         $languages = LanguageHelper::getLanguageModels();
         $models = [];
         foreach ($languages as $language) {
             if ($language->locale === LanguageHelper::getDefaultLanguage()->locale) {
                 continue;
             }
             $models[$language->locale] = $model->getTranslation($language->locale);
         }
         if (!empty($models)) {
             $loaded &= Model::loadMultiple($models, Yii::$app->request->post());
         }
     }
     $loaded = $model->load(Yii::$app->request->post()) && $loaded;
     return $loaded;
 }
開發者ID:tolik505,項目名稱:bl,代碼行數:24,代碼來源:BackendController.php


注:本文中的yii\db\ActiveRecord::getTranslation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。