Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function saveUser($user) {
- if ($user['id'] != null) { //update
- $entity = $this->getUser($user['id']);
- //do something
- if (!$entity)
- throw new Exception('Error saving user!');
- } else { //insert
- $modelCountries = array();
- $entity = new User();
- $entity->email = $user['email'];
- $entity->responsable = $user['responsable'];
- $entity->password = $this->createPass($user['password']);
- $entity->url = $user['url'];
- $entity->role = $user['role'];
- foreach ($user['countries'] as $country) {
- $p = new Countries();
- $p->countryName = $country;
- $p->user = $entity;
- $modelCountries[] = $p;
- }
- $entity->countries = $modelCountries;
- }
- $this->em->persist($entity);
- $this->em->flush(); //save the user
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement