Commit db63ba79a963429084fb696749e3a496e576ee84
1 parent
94a1dbd2
-User's data form ready
Showing
4 changed files
with
169 additions
and
90 deletions
Show diff stats
composer.json
@@ -34,7 +34,8 @@ | @@ -34,7 +34,8 @@ | ||
34 | "phpoffice/phpexcel": "^1.8", | 34 | "phpoffice/phpexcel": "^1.8", |
35 | "bower-asset/amcharts": "@dev", | 35 | "bower-asset/amcharts": "@dev", |
36 | "bower-asset/pnotify": "@dev", | 36 | "bower-asset/pnotify": "@dev", |
37 | - "kartik-v/yii2-widget-colorinput": "*" | 37 | + "kartik-v/yii2-widget-colorinput": "*", |
38 | + "kartik-v/yii2-widget-datepicker": "@dev" | ||
38 | }, | 39 | }, |
39 | "require-dev": { | 40 | "require-dev": { |
40 | "yiisoft/yii2-debug": "~2.0.0", | 41 | "yiisoft/yii2-debug": "~2.0.0", |
composer.lock
@@ -4,8 +4,8 @@ | @@ -4,8 +4,8 @@ | ||
4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", | 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", |
5 | "This file is @generated automatically" | 5 | "This file is @generated automatically" |
6 | ], | 6 | ], |
7 | - "hash": "482c96d17c08496f9d67ccef1d071cc3", | ||
8 | - "content-hash": "ea8f4f552cdc9b0c7ac2eeb4ae9afa66", | 7 | + "hash": "b18802ddb055188c55f12e121f5e14cf", |
8 | + "content-hash": "74adfbddeb0bd9b6f951a699924afa86", | ||
9 | "packages": [ | 9 | "packages": [ |
10 | { | 10 | { |
11 | "name": "2amigos/yii2-tinymce-widget", | 11 | "name": "2amigos/yii2-tinymce-widget", |
@@ -1388,6 +1388,60 @@ | @@ -1388,6 +1388,60 @@ | ||
1388 | "time": "2016-01-14 11:15:49" | 1388 | "time": "2016-01-14 11:15:49" |
1389 | }, | 1389 | }, |
1390 | { | 1390 | { |
1391 | + "name": "kartik-v/yii2-widget-datepicker", | ||
1392 | + "version": "dev-master", | ||
1393 | + "source": { | ||
1394 | + "type": "git", | ||
1395 | + "url": "https://github.com/kartik-v/yii2-widget-datepicker.git", | ||
1396 | + "reference": "9110ecce9deb59dc116fe6c3dd6df5d7eb439a3c" | ||
1397 | + }, | ||
1398 | + "dist": { | ||
1399 | + "type": "zip", | ||
1400 | + "url": "https://api.github.com/repos/kartik-v/yii2-widget-datepicker/zipball/9110ecce9deb59dc116fe6c3dd6df5d7eb439a3c", | ||
1401 | + "reference": "9110ecce9deb59dc116fe6c3dd6df5d7eb439a3c", | ||
1402 | + "shasum": "" | ||
1403 | + }, | ||
1404 | + "require": { | ||
1405 | + "kartik-v/yii2-krajee-base": "~1.7" | ||
1406 | + }, | ||
1407 | + "type": "yii2-extension", | ||
1408 | + "extra": { | ||
1409 | + "branch-alias": { | ||
1410 | + "dev-master": "1.4.x-dev" | ||
1411 | + } | ||
1412 | + }, | ||
1413 | + "autoload": { | ||
1414 | + "psr-4": { | ||
1415 | + "kartik\\date\\": "" | ||
1416 | + } | ||
1417 | + }, | ||
1418 | + "notification-url": "https://packagist.org/downloads/", | ||
1419 | + "license": [ | ||
1420 | + "BSD-3-Clause" | ||
1421 | + ], | ||
1422 | + "authors": [ | ||
1423 | + { | ||
1424 | + "name": "Kartik Visweswaran", | ||
1425 | + "email": "kartikv2@gmail.com", | ||
1426 | + "homepage": "http://www.krajee.com/" | ||
1427 | + } | ||
1428 | + ], | ||
1429 | + "description": "Enhanced Yii2 wrapper for the bootstrap datepicker plugin (sub repo split from yii2-widgets).", | ||
1430 | + "homepage": "https://github.com/kartik-v/yii2-widget-datepicker", | ||
1431 | + "keywords": [ | ||
1432 | + "date", | ||
1433 | + "extension", | ||
1434 | + "form", | ||
1435 | + "jquery", | ||
1436 | + "picker", | ||
1437 | + "plugin", | ||
1438 | + "select2", | ||
1439 | + "widget", | ||
1440 | + "yii2" | ||
1441 | + ], | ||
1442 | + "time": "2017-04-01 16:03:50" | ||
1443 | + }, | ||
1444 | + { | ||
1391 | "name": "kartik-v/yii2-widget-fileinput", | 1445 | "name": "kartik-v/yii2-widget-fileinput", |
1392 | "version": "v1.0.5", | 1446 | "version": "v1.0.5", |
1393 | "source": { | 1447 | "source": { |
@@ -4825,7 +4879,8 @@ | @@ -4825,7 +4879,8 @@ | ||
4825 | "bower-asset/amcharts-stock": 20, | 4879 | "bower-asset/amcharts-stock": 20, |
4826 | "kartik-v/yii2-widget-select2": 20, | 4880 | "kartik-v/yii2-widget-select2": 20, |
4827 | "bower-asset/amcharts": 20, | 4881 | "bower-asset/amcharts": 20, |
4828 | - "bower-asset/pnotify": 20 | 4882 | + "bower-asset/pnotify": 20, |
4883 | + "kartik-v/yii2-widget-datepicker": 20 | ||
4829 | }, | 4884 | }, |
4830 | "prefer-stable": false, | 4885 | "prefer-stable": false, |
4831 | "prefer-lowest": false, | 4886 | "prefer-lowest": false, |
frontend/controllers/AccountController.php
@@ -72,9 +72,11 @@ | @@ -72,9 +72,11 @@ | ||
72 | 72 | ||
73 | public function actionAccount() | 73 | public function actionAccount() |
74 | { | 74 | { |
75 | + $user = \Yii::$app->user->identity; | ||
75 | return $this->render( | 76 | return $this->render( |
76 | 'account', | 77 | 'account', |
77 | [ | 78 | [ |
79 | + 'userModel' => $user, | ||
78 | 'passwordModel' => new PasswordForm(), | 80 | 'passwordModel' => new PasswordForm(), |
79 | ] | 81 | ] |
80 | ); | 82 | ); |
@@ -87,7 +89,7 @@ | @@ -87,7 +89,7 @@ | ||
87 | */ | 89 | */ |
88 | $model = new PasswordForm(); | 90 | $model = new PasswordForm(); |
89 | $modeluser = \Yii::$app->user->identity; | 91 | $modeluser = \Yii::$app->user->identity; |
90 | - | 92 | + |
91 | if ($model->load(\Yii::$app->request->post())) { | 93 | if ($model->load(\Yii::$app->request->post())) { |
92 | if ($model->validate()) { | 94 | if ($model->validate()) { |
93 | $modeluser->setPassword($model->newpass); | 95 | $modeluser->setPassword($model->newpass); |
@@ -97,6 +99,7 @@ | @@ -97,6 +99,7 @@ | ||
97 | return $this->render( | 99 | return $this->render( |
98 | 'account', | 100 | 'account', |
99 | [ | 101 | [ |
102 | + 'userModel' => $modeluser, | ||
100 | 'passwordModel' => $model, | 103 | 'passwordModel' => $model, |
101 | ] | 104 | ] |
102 | ); | 105 | ); |
@@ -105,17 +108,42 @@ | @@ -105,17 +108,42 @@ | ||
105 | return $this->render( | 108 | return $this->render( |
106 | 'account', | 109 | 'account', |
107 | [ | 110 | [ |
111 | + 'userModel' => $modeluser, | ||
108 | 'passwordModel' => $model, | 112 | 'passwordModel' => $model, |
109 | ] | 113 | ] |
110 | ); | 114 | ); |
111 | } | 115 | } |
112 | - } else { | ||
113 | - return $this->render( | ||
114 | - 'account', | ||
115 | - [ | ||
116 | - 'passwordModel' => $model, | ||
117 | - ] | ||
118 | - ); | ||
119 | } | 116 | } |
117 | + return $this->render( | ||
118 | + 'account', | ||
119 | + [ | ||
120 | + 'userModel' => $modeluser, | ||
121 | + 'passwordModel' => $model, | ||
122 | + ] | ||
123 | + ); | ||
124 | + | ||
125 | + } | ||
126 | + | ||
127 | + public function actionChangeData() | ||
128 | + { | ||
129 | + /** | ||
130 | + * @var Customer $model | ||
131 | + */ | ||
132 | + $model = \Yii::$app->user->identity; | ||
133 | + | ||
134 | + if ($model->load(\Yii::$app->request->post())) { | ||
135 | + // VarDumper::dump($model, 10, 1);die(); | ||
136 | + $model->markAttributeDirty('birthday'); | ||
137 | + if ($model->save()) { | ||
138 | + return $this->redirect([ 'index' ]); | ||
139 | + } | ||
140 | + } | ||
141 | + return $this->render( | ||
142 | + 'account', | ||
143 | + [ | ||
144 | + 'userModel' => $model, | ||
145 | + 'passwordModel' => new PasswordForm(), | ||
146 | + ] | ||
147 | + ); | ||
120 | } | 148 | } |
121 | } | 149 | } |
122 | \ No newline at end of file | 150 | \ No newline at end of file |
frontend/views/account/account.php
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | + use artbox\order\models\Customer; | ||
3 | use artbox\order\models\PasswordForm; | 4 | use artbox\order\models\PasswordForm; |
5 | + use kartik\date\DatePicker; | ||
4 | use yii\helpers\Html; | 6 | use yii\helpers\Html; |
5 | use yii\web\View; | 7 | use yii\web\View; |
6 | use yii\widgets\ActiveForm; | 8 | use yii\widgets\ActiveForm; |
@@ -8,6 +10,7 @@ | @@ -8,6 +10,7 @@ | ||
8 | /** | 10 | /** |
9 | * @var View $this | 11 | * @var View $this |
10 | * @var PasswordForm $passwordModel | 12 | * @var PasswordForm $passwordModel |
13 | + * @var Customer $userModel | ||
11 | */ | 14 | */ |
12 | 15 | ||
13 | $this->params[ 'breadcrumbs' ][] = \Yii::t('app', 'Мой аккаунт'); | 16 | $this->params[ 'breadcrumbs' ][] = \Yii::t('app', 'Мой аккаунт'); |
@@ -72,87 +75,79 @@ _________________________________________________________ --> | @@ -72,87 +75,79 @@ _________________________________________________________ --> | ||
72 | <div class="heading"> | 75 | <div class="heading"> |
73 | <h3 class="text-uppercase">Персональные данные</h3> | 76 | <h3 class="text-uppercase">Персональные данные</h3> |
74 | </div> | 77 | </div> |
75 | - | ||
76 | - <form> | ||
77 | - <div class="row"> | ||
78 | - <div class="col-sm-6"> | ||
79 | - <div class="form-group"> | ||
80 | - <label for="firstname">Имя</label> | ||
81 | - <input type="text" class="form-control" id="firstname"> | ||
82 | - </div> | ||
83 | - </div> | ||
84 | - <div class="col-sm-6"> | ||
85 | - <div class="form-group"> | ||
86 | - <label for="lastname">Фамилия</label> | ||
87 | - <input type="text" class="form-control" id="lastname"> | ||
88 | - </div> | ||
89 | - </div> | 78 | + |
79 | + <?php $userForm = ActiveForm::begin( | ||
80 | + [ | ||
81 | + 'action' => [ 'account/change-data' ], | ||
82 | + ] | ||
83 | + ) ?> | ||
84 | + <div class="row"> | ||
85 | + <div class="col-sm-6"> | ||
86 | + <?= $userForm->field($userModel, 'name') ?> | ||
90 | </div> | 87 | </div> |
91 | - <!-- /.row --> | ||
92 | - | ||
93 | - <div class="row"> | ||
94 | - <div class="col-sm-6"> | ||
95 | - <div class="form-group"> | ||
96 | - <label for="company">Фирма</label> | ||
97 | - <input type="text" class="form-control" id="company"> | ||
98 | - </div> | ||
99 | - </div> | ||
100 | - <div class="col-sm-6"> | ||
101 | - <div class="form-group"> | ||
102 | - <label for="street">Улица</label> | ||
103 | - <input type="text" class="form-control" id="street"> | ||
104 | - </div> | ||
105 | - </div> | 88 | + <div class="col-sm-6"> |
89 | + <?= $userForm->field($userModel, 'address') | ||
90 | + ->textInput() ?> | ||
106 | </div> | 91 | </div> |
107 | - <!-- /.row --> | ||
108 | - | ||
109 | - <div class="row"> | ||
110 | - <div class="col-sm-6 col-md-3"> | ||
111 | - <div class="form-group"> | ||
112 | - <label for="city">Город</label> | ||
113 | - <input type="text" class="form-control" id="city"> | ||
114 | - </div> | ||
115 | - </div> | ||
116 | - <div class="col-sm-6 col-md-3"> | ||
117 | - <div class="form-group"> | ||
118 | - <label for="zip">Индекс</label> | ||
119 | - <input type="text" class="form-control" id="zip"> | ||
120 | - </div> | ||
121 | - </div> | ||
122 | - <div class="col-sm-6 col-md-3"> | ||
123 | - <div class="form-group"> | ||
124 | - <label for="state">Область</label> | ||
125 | - <select class="form-control" id="state"></select> | ||
126 | - </div> | ||
127 | - </div> | ||
128 | - <div class="col-sm-6 col-md-3"> | ||
129 | - <div class="form-group"> | ||
130 | - <label for="country">Страна</label> | ||
131 | - <select class="form-control" id="country"></select> | ||
132 | - </div> | ||
133 | - </div> | ||
134 | - | ||
135 | - <div class="col-sm-6"> | ||
136 | - <div class="form-group"> | ||
137 | - <label for="phone">Телефон</label> | ||
138 | - <input type="text" class="form-control" id="phone"> | ||
139 | - </div> | ||
140 | - </div> | ||
141 | - <div class="col-sm-6"> | ||
142 | - <div class="form-group"> | ||
143 | - <label for="email_account">E-mail</label> | ||
144 | - <input type="text" class="form-control" id="email_account"> | ||
145 | - </div> | ||
146 | - </div> | ||
147 | - <div class="col-sm-12 text-center"> | ||
148 | - <button type="submit" class="btn btn-template-main"><i class="fa fa-save"></i> Сохранить изменения | ||
149 | - </button> | ||
150 | - | ||
151 | - </div> | ||
152 | - | 92 | + </div> |
93 | + <!-- /.row --> | ||
94 | + | ||
95 | + <div class="row"> | ||
96 | + <div class="col-sm-6 col-md-3"> | ||
97 | + <?= $userForm->field($userModel, 'city') | ||
98 | + ->textInput() ?> | ||
153 | </div> | 99 | </div> |
154 | - | ||
155 | - </form> | 100 | + <div class="col-sm-6 col-md-3"> |
101 | + <?= $userForm->field($userModel, 'gender') | ||
102 | + ->dropDownList( | ||
103 | + [ | ||
104 | + 1 => \Yii::t('app', 'Муж.'), | ||
105 | + 2 => \Yii::t('app', 'Жен.'), | ||
106 | + ], | ||
107 | + [ | ||
108 | + 'prompt' => \Yii::t('app', 'Пол'), | ||
109 | + ] | ||
110 | + ) ?> | ||
111 | + </div> | ||
112 | + <div class="col-sm-6 col-md-6"> | ||
113 | + <?= $userForm->field($userModel, 'email') | ||
114 | + ->textInput() ?> | ||
115 | + </div> | ||
116 | + | ||
117 | + </div> | ||
118 | + <div class="row"> | ||
119 | + | ||
120 | + <div class="col-sm-6"> | ||
121 | + <?= $userForm->field($userModel, 'phone') | ||
122 | + ->textInput() ?> | ||
123 | + | ||
124 | + </div> | ||
125 | + <div class="col-sm-6"> | ||
126 | + <?= $userForm->field($userModel, 'birthDate') | ||
127 | + ->widget( | ||
128 | + DatePicker::className(), | ||
129 | + [ | ||
130 | + 'options' => [ | ||
131 | + 'placeholder' => \Yii::t('app', 'Дата рождения ...'), | ||
132 | + ], | ||
133 | + 'pluginOptions' => [ | ||
134 | + 'autoclose' => true, | ||
135 | + 'format' => 'dd.mm.yyyy', | ||
136 | + ], | ||
137 | + ] | ||
138 | + ) ?> | ||
139 | + </div> | ||
140 | + <div class="col-sm-12 text-center"> | ||
141 | + <?= Html::submitButton( | ||
142 | + '<i class="fa fa-save"></i> Сохранить изменения', | ||
143 | + [ | ||
144 | + 'class' => 'btn btn-template-main', | ||
145 | + ] | ||
146 | + ) ?> | ||
147 | + </div> | ||
148 | + </div> | ||
149 | + | ||
150 | + <?php $userForm::end(); ?> | ||
156 | 151 | ||
157 | </div> | 152 | </div> |
158 | 153 |