/** * @static * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocatorInterface * @return RoleDAO */ public static function getInstance(ServiceLocatorInterface $serviceLocatorInterface) { if (self::$instance == null) { self::$instance = new RoleDAO(); self::$instance->setServiceLocator($serviceLocatorInterface); } return self::$instance; }
public function addAction() { $form = new UserForm(); $request = $this->getRequest(); $userDAO = UserDAO::getInstance($this->getServiceLocator()); if ($request->isPost()) { $post = $request->getPost()->toArray(); $form->setData($post); if ($form->isValid()) { $data = $form->getData(); $userData = new User(); $userData->setDisplayName($data['displayName']); $userData->setEmail($data['email']); $userData->setPassword(md5($data['password'])); $userData->setRole(RoleDAO::getInstance($this->getServiceLocator())->findOneById($data['role'])); $userDAO->save($userData); return $this->redirect()->toRoute('users'); } else { $form->getMessages(); } } return array('form' => $form); }