Advertisement
Guest User

Untitled

a guest
Sep 18th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. public function saveUser($user) {
  2. if ($user['id'] != null) { //update
  3. $entity = $this->getUser($user['id']);
  4.  
  5. //do something
  6.  
  7. if (!$entity)
  8. throw new Exception('Error saving user!');
  9. } else { //insert
  10. $modelCountries = array();
  11. $entity = new User();
  12. $entity->email = $user['email'];
  13. $entity->responsable = $user['responsable'];
  14. $entity->password = $this->createPass($user['password']);
  15. $entity->url = $user['url'];
  16. $entity->role = $user['role'];
  17. foreach ($user['countries'] as $country) {
  18. $p = new Countries();
  19. $p->countryName = $country;
  20. $p->user = $entity;
  21. $modelCountries[] = $p;
  22. }
  23. $entity->countries = $modelCountries;
  24. }
  25.  
  26. $this->em->persist($entity);
  27. $this->em->flush(); //save the user
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement