Advertisement
Guest User

Untitled

a guest
Sep 8th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. Pisane na szybko, po 4 piwkach z głowy. Wersja ogólnie uproszczona.
  2.  
  3. Klasa kontrolera, powiedzmy user, a w niej funkcja do edycji maila.
  4.  
  5. public function editEmail() {
  6.     try{
  7.         // wywołuje model o tej samej funkcji
  8.         $this->model->editEmail($_POST['email']);
  9.         // zwraca status
  10.         $status = ["status"=>true, "message"=>"Nie ma lipy :)"];
  11.     } catch(\Exception $e) {
  12.         $status = ["status"=>false, "message"=>$e->getMessage()];
  13.     }
  14.  
  15.     echo json_encode($status);        
  16.  
  17. }
  18.  
  19. Tutaj model, tutaj robię walidację. W klasie "User" już tego nie sprawdzam
  20.  
  21. public function editEmail(string $email) : bool {
  22.  
  23.     $val = new \Utils\Validiator();
  24.     $val->pattern("email", $email);
  25.     // sprawdzam czy success
  26.     if($val->isSuccess() === false) {
  27.         throw new \Exception("Lipa :(");
  28.     }
  29.     return true;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement