Witam,
zrobiłem sobie formularz zmiany danych w bazie, ale po zapisie pobierane są ponownie jakby stare dane albo są trzymane gdzieś w pamięci... chociaż wątpię, bo w logach strony, które stworzyłem jestem w stanie od razu po kliknięciu zobaczyć nowe dane.

  1. <?php
  2. namespace src\cms\controller;
  3.  
  4. use src\cms\controller\Controller;
  5. use src\cms\controller\IController;
  6. use src\cms\model\UsersModel;
  7.  
  8. class SettingsController extends Controller implements IController
  9. {
  10. private $usersModel;
  11. private $currentLoggedUser;
  12.  
  13. public function __construct()
  14. {
  15. parent::__construct();
  16.  
  17. $this->usersModel = new UsersModel();
  18. }
  19.  
  20. public function __destruct()
  21. {
  22. parent::displayBase();
  23. }
  24.  
  25. public function indexAction()
  26. {
  27. $this->currentLoggedUser = $this->usersModel->getUserByUsername($_SESSION['username']);
  28.  
  29. $this->view->first_name = $this->currentLoggedUser[0]['first_name'];
  30. $this->view->email = $this->currentLoggedUser[0]['email_address'];
  31.  
  32. if (isset($_POST['save']))
  33. $this->checkData();
  34.  
  35. $this->view->baseContent = $this->view->display('src/cms/data/templates/settings.php');
  36. }
  37.  
  38. /**
  39.   * Checks the data from form while changing the user data
  40.   */
  41. private function checkData()
  42. {
  43. if ($_POST['old_password'] == $this->currentLoggedUser[0]['password'] && $_SESSION['rank'] == 'admin') //Checks if the logged user is admin
  44. $this->changeData();
  45. else
  46. \simonmedia\package\log\Logs::warn('SettingsController (cms)', 'The given password is not the same as in database');
  47. }
  48.  
  49. /**
  50.   * Changes the data of the current logged user
  51.   */
  52. private function changeData()
  53. {
  54. $oldName = $this->currentLoggedUser[0]['first_name'];
  55.  
  56. $name = $_POST['first_name'];
  57. $emailAddress = $_POST['email_address'];
  58. $newPassword = $_POST['new_password'];
  59. $rePassword = $_POST['re_password'];
  60.  
  61. if ($newPassword !== $rePassword)
  62. \simonmedia\package\log\Logs::warn('SettingsController (cms)', 'New password and the repeat password is not the same');
  63. else
  64. $this->usersModel->setNewData($oldName, $name, $emailAddress, $newPassword);
  65. }
  66.  
  67. }
  68.  


To jest ta klasa.
Sam formularz kieruje na tą samą stronę, z której został wywołany.

W liniach 29, 30 są wysyłane do widoku (do formualrza) dane z bazy.
Mniej więcej wiem, gdzie leży problem, ale czy stare dane są jakby zachowywane w danym przesłaniu?
Gdy na końcu czyli w changeData zrobię
  1. var_dump($this->usersModel->getUserByUsername($_SESSION['username']));

to zwraca mi od razu nową nazwę już po zmianie.

Jakieś sugestie macie jak to załatwić?
Myślałem o ajax i wysłanie żądania z formularza do php przez ajax i odebranie danych, ale czy to ma sens?

Przy okazji proszę o ocenę klasy (nie duża, ale chyba pierwsza do oceny)

Dodam, że skrypt potrafi sobie zmieniać na zmianę nawet.

Tutaj możecie to sprawdzć: simonmedia.gtbase.net/panel
Login: admin
Hasło: superhaslo

Wygląda to tak, jakby nie odświeżał - lub nie pobierał świeżych danych z db.

UPDATE:

Chyba naprawiłem sobie to tym:
  1. private function changeData()
  2. {
  3. $oldName = $this->currentLoggedUser[0]['first_name'];
  4.  
  5. $name = $_POST['first_name'];
  6. $emailAddress = $_POST['email_address'];
  7. $newPassword = $_POST['new_password'];
  8. $rePassword = $_POST['re_password'];
  9. \simonmedia\package\log\Logs::warn('SettingsController (cms)', 'New password and the repeat password is not the same');
  10.  
  11. if ($newPassword !== $rePassword)
  12. \simonmedia\package\log\Logs::warn('SettingsController (cms)', 'New password and the repeat password is not the same');
  13. else
  14. $this->usersModel->setNewData($oldName, $name, $emailAddress, $newPassword);
  15.  
  16. header('refresh:0.01; url=http://cms/panel/ustawienia');
  17. }


No i logi działają, bo bez czasowe refreshu było to wykonywane od razu i jakby logi były pomijane.
Oczywiście będzie to zautomatyzowane.