Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AccountController
- {
- public function signupSubmit() {
- // USING METHOD #1:
- $repo = $this->getEntityManagerService()->getRepository('Mediabin\Model\Entity\User');
- $user = $repo->createUser($username, $password, ... );
- // USING METHOD #2:
- $user = new User($username, $password,...);
- $this->getEntityManagerService()->persist($user);
- $this->getEntityManagerService()->flush();
- }
- }
- // METHOD #1: CREATE IN THE REPOSITORY
- class UserRepository extends EntityRepository // Created by doctrine, have no access to constructor
- {
- public function create($username, $password)
- {
- $user = new User();
- $user->setUsername($username)->setPassword($password) ...
- $this->_em->persist($user);
- $this->_em->flush();
- return $user;
- }
- }
- // METHOD #2: CREATE IN THE ENTITY
- class User extends Entity // Created by doctrine, have access to constructor directly, but only on new objects
- {
- public function create($username, $password, ...)
- {
- $this->username = $username;
- $this->password = $password; // encrypt here, or in controller?
- $this->registeredDate = new DateTime('now');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement