Drupal investigation

UpdateForm.php 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. use yii\base\Model;
  5. use app\models\TestUsers;
  6. class UpdateForm extends Model
  7. {
  8. public $username;
  9. public $accessToken;
  10. public $authKey;
  11. public $password;
  12. public $forename;
  13. public $surname;
  14. public $email;
  15. public $phone;
  16. public $lang;
  17. public function rules(){
  18. return [
  19. ['email', 'trim'],
  20. ['email', 'string', 'min' => 2, 'max' => 255],
  21. ['phone', 'trim'],
  22. ['phone', 'string', 'min' => 2, 'max' => 32],
  23. ['lang', 'string', 'min' => 2, 'max' => 10],
  24. ];
  25. }
  26. public function update(){
  27. if ($this->validate()){
  28. $user = TestUsers::findOne(Yii::$app->user->id);
  29. if ($this->email !== '') {
  30. $user->email = $this->email;
  31. }
  32. if ($this->phone !== '') {
  33. $user->phone = $this->phone;
  34. }
  35. $user->lang = $this->lang;
  36. Yii::$app->language = $this->lang;
  37. $user->save();
  38. return true;
  39. }
  40. return false;
  41. }
  42. }