Advertisement
Guest User

Untitled

a guest
Jun 4th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. class AccountController
  2. {
  3. public function signupSubmit() {
  4. // USING METHOD #1:
  5.  
  6. $repo = $this->getEntityManagerService()->getRepository('Mediabin\Model\Entity\User');
  7. $user = $repo->createUser($username, $password, ... );
  8.  
  9. // USING METHOD #2:
  10.  
  11. $user = new User($username, $password,...);
  12. $this->getEntityManagerService()->persist($user);
  13. $this->getEntityManagerService()->flush();
  14. }
  15. }
  16.  
  17. // METHOD #1: CREATE IN THE REPOSITORY
  18.  
  19. class UserRepository extends EntityRepository // Created by doctrine, have no access to constructor
  20. {
  21. public function create($username, $password)
  22. {
  23. $user = new User();
  24. $user->setUsername($username)->setPassword($password) ...
  25.  
  26. $this->_em->persist($user);
  27. $this->_em->flush();
  28. return $user;
  29. }
  30. }
  31.  
  32. // METHOD #2: CREATE IN THE ENTITY
  33.  
  34. class User extends Entity // Created by doctrine, have access to constructor directly, but only on new objects
  35. {
  36. public function create($username, $password, ...)
  37. {
  38. $this->username = $username;
  39. $this->password = $password; // encrypt here, or in controller?
  40. $this->registeredDate = new DateTime('now');
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement