123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace app\models;
- use Yii;
- use yii\base\Model;
- use app\models\TestUsers;
- class UpdateForm extends Model
- {
- public $username;
- public $accessToken;
- public $authKey;
- public $password;
- public $forename;
- public $surname;
- public $email;
- public $phone;
- public $lang;
- public function rules(){
- return [
- ['email', 'trim'],
- ['email', 'string', 'min' => 2, 'max' => 255],
- ['phone', 'trim'],
- ['phone', 'string', 'min' => 2, 'max' => 32],
- ['lang', 'string', 'min' => 2, 'max' => 10],
- ];
- }
- public function update(){
- if ($this->validate()){
- $user = TestUsers::findOne(Yii::$app->user->id);
- if ($this->email !== '') {
- $user->email = $this->email;
- }
- if ($this->phone !== '') {
- $user->phone = $this->phone;
- }
- $user->lang = $this->lang;
- Yii::$app->language = $this->lang;
- $user->save();
- return true;
- }
- return false;
- }
- }
|