Commit a92850cf18821a85e778f7055dcf08b7d362c972
1 parent
4668085e
firs page
Showing
4 changed files
with
40 additions
and
3 deletions
Show diff stats
common/widgets/FieldEditor.php
| 1 | <?php | 1 | <?php |
| 2 | namespace common\widgets; | 2 | namespace common\widgets; |
| 3 | use common\models\Fields; | 3 | use common\models\Fields; |
| 4 | +use common\models\Language; | ||
| 4 | use yii\base\Widget; | 5 | use yii\base\Widget; |
| 5 | 6 | ||
| 6 | 7 | ||
| @@ -9,6 +10,7 @@ class FieldEditor extends Widget | @@ -9,6 +10,7 @@ class FieldEditor extends Widget | ||
| 9 | public $item_id; | 10 | public $item_id; |
| 10 | public $model; | 11 | public $model; |
| 11 | public $template; | 12 | public $template; |
| 13 | + public $language; | ||
| 12 | 14 | ||
| 13 | public function init(){ | 15 | public function init(){ |
| 14 | 16 | ||
| @@ -31,7 +33,12 @@ class FieldEditor extends Widget | @@ -31,7 +33,12 @@ class FieldEditor extends Widget | ||
| 31 | 33 | ||
| 32 | protected function findModel() | 34 | protected function findModel() |
| 33 | { | 35 | { |
| 34 | - if (($model = Fields::find()->where(['table_id'=>$this->item_id, 'table_name'=>$this->model, 'field_type'=>$this->template])->all()) !== null) { | 36 | + if (($model = Fields::find()->where([ |
| 37 | + 'table_id'=>$this->item_id, | ||
| 38 | + 'table_name'=>$this->model, | ||
| 39 | + 'field_type'=>$this->template, | ||
| 40 | + 'language'=>$this->language, | ||
| 41 | + ])->all())) { | ||
| 35 | 42 | ||
| 36 | return $model; | 43 | return $model; |
| 37 | 44 |
| 1 | +<?php | ||
| 2 | +use yii\helpers\Html; | ||
| 3 | +?> | ||
| 4 | +<fieldset> | ||
| 5 | + | ||
| 6 | + <legend>Video</legend> | ||
| 7 | + | ||
| 8 | + <p class="btn btn-success add_field">Добавить поле</p> | ||
| 9 | + | ||
| 10 | + | ||
| 11 | + | ||
| 12 | + <div class="price_fields_result"> | ||
| 13 | + <?php $i=0; foreach ($model as $field):?> | ||
| 14 | + <?= Html::beginTag('div',['class'=>'form-group'])?> | ||
| 15 | + <input type="text" placeholder="Описание" class="form-control" value="<?= $field->field_name ?>" name="Fields[education][<?=$i?>][description]" /> | ||
| 16 | + <input type="text" placeholder="Цена" class="form-control" value="<?= $field->value ?>" name="Fields[education][<?=$i++?>][value]" /> | ||
| 17 | + <span data-id="<?= $field->id ?>" title="удалить" class="glyphicon glyphicon-trash delete-field-item"></span> | ||
| 18 | + <?= Html::endTag('div')?> | ||
| 19 | + <?php endforeach; ?> | ||
| 20 | + </div> | ||
| 21 | + | ||
| 22 | +</fieldset> | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + |
console/migrations/m160128_101543_fields.php
| @@ -15,7 +15,7 @@ class m160128_101543_fields extends Migration | @@ -15,7 +15,7 @@ class m160128_101543_fields extends Migration | ||
| 15 | 'value' => $this->string(255), | 15 | 'value' => $this->string(255), |
| 16 | 'field_name' => $this->string(), | 16 | 'field_name' => $this->string(), |
| 17 | 'field_type' => $this->string(32)->notNull(), | 17 | 'field_type' => $this->string(32)->notNull(), |
| 18 | - 'language' => $this->integer() | 18 | + 'language' => $this->string(3) |
| 19 | ], $tableOptions); | 19 | ], $tableOptions); |
| 20 | 20 | ||
| 21 | } | 21 | } |
frontend/views/accounts/_form.php
| @@ -49,7 +49,12 @@ use yii\widgets\ActiveForm; | @@ -49,7 +49,12 @@ use yii\widgets\ActiveForm; | ||
| 49 | 49 | ||
| 50 | <?= $form->field($user_info, 'about')->textarea(['rows' => 6]) ?> | 50 | <?= $form->field($user_info, 'about')->textarea(['rows' => 6]) ?> |
| 51 | 51 | ||
| 52 | -<?= \common\widgets\FieldEditor::widget(['template'=>'', 'item_id'=> $user->id, 'model'=>'User']); ?> | 52 | +<?= \common\widgets\FieldEditor::widget([ |
| 53 | + 'template'=>'education', | ||
| 54 | + 'item_id'=> $user->id, | ||
| 55 | + 'model'=>'User', | ||
| 56 | + 'language'=>'ru' | ||
| 57 | +]); ?> | ||
| 53 | 58 | ||
| 54 | 59 | ||
| 55 | <div class="form-group"> | 60 | <div class="form-group"> |