Commit 4668085ef587793dce2e167df6d5f3d80d4be34b
1 parent
6af40417
firs page
Showing
4 changed files
with
86 additions
and
2 deletions
Show diff stats
1 | +<?php | ||
2 | + | ||
3 | +namespace common\models; | ||
4 | + | ||
5 | +use Yii; | ||
6 | + | ||
7 | +/** | ||
8 | + * This is the model class for table "{{%fields}}". | ||
9 | + * | ||
10 | + * @property integer $id | ||
11 | + * @property string $table_name | ||
12 | + * @property integer $table_id | ||
13 | + * @property string $value | ||
14 | + * @property string $field_name | ||
15 | + * @property string $field_type | ||
16 | + */ | ||
17 | +class Fields extends \yii\db\ActiveRecord | ||
18 | +{ | ||
19 | + /** | ||
20 | + * @inheritdoc | ||
21 | + */ | ||
22 | + public static function tableName() | ||
23 | + { | ||
24 | + return '{{%fields}}'; | ||
25 | + } | ||
26 | + | ||
27 | + /** | ||
28 | + * @inheritdoc | ||
29 | + */ | ||
30 | + public function rules() | ||
31 | + { | ||
32 | + return [ | ||
33 | + [['table_name', 'table_id',], 'required'], | ||
34 | + [['table_id','language'], 'integer'], | ||
35 | + [['table_name', 'value', 'field_name','field_type'], 'string', 'max' => 255] | ||
36 | + ]; | ||
37 | + } | ||
38 | + | ||
39 | + /** | ||
40 | + * @inheritdoc | ||
41 | + */ | ||
42 | + public function attributeLabels() | ||
43 | + { | ||
44 | + return [ | ||
45 | + 'id' => 'ID', | ||
46 | + 'table_name' => 'Model Name', | ||
47 | + 'table_id' => 'Model ID', | ||
48 | + 'value' => 'Value', | ||
49 | + 'field_name' => 'Field Name', | ||
50 | + 'language' => 'Language', | ||
51 | + ]; | ||
52 | + } | ||
53 | + | ||
54 | + public static function getData($id, $model, $type){ | ||
55 | + return self::find()->where(['table_id'=>$id, 'table_name'=>$model, 'field_type'=>$type])->all(); | ||
56 | + } | ||
57 | +} |
common/widgets/FieldEditor.php
1 | +<?php | ||
2 | + | ||
3 | +use yii\db\Migration; | ||
4 | + | ||
5 | +class m160128_101543_fields extends Migration | ||
6 | +{ | ||
7 | + public function up() | ||
8 | + { | ||
9 | + $tableOptions = null; | ||
10 | + | ||
11 | + $this->createTable('{{%fields}}', [ | ||
12 | + 'id' => $this->primaryKey(), | ||
13 | + 'table_name' => $this->string(255)->notNull(), | ||
14 | + 'table_id' => $this->integer(), | ||
15 | + 'value' => $this->string(255), | ||
16 | + 'field_name' => $this->string(), | ||
17 | + 'field_type' => $this->string(32)->notNull(), | ||
18 | + 'language' => $this->integer() | ||
19 | + ], $tableOptions); | ||
20 | + | ||
21 | + } | ||
22 | + | ||
23 | + public function down() | ||
24 | + { | ||
25 | + $this->dropTable('{{%fields}}'); | ||
26 | + } | ||
27 | +} |
frontend/views/accounts/_form.php
@@ -49,7 +49,7 @@ use yii\widgets\ActiveForm; | @@ -49,7 +49,7 @@ 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(['item_id'=> $model->id, 'model'=>'Gallery']); ?> | 52 | +<?= \common\widgets\FieldEditor::widget(['template'=>'', 'item_id'=> $user->id, 'model'=>'User']); ?> |
53 | 53 | ||
54 | 54 | ||
55 | <div class="form-group"> | 55 | <div class="form-group"> |