public function save(User $user)
 {
     $data = array('username' => $user->getUsername(), 'password' => $user->getPassword(), 'name' => $user->getName(), 'valid' => $user->getValid(), 'role' => $user->getRole());
     $id = (int) $user->getId();
     if ($id == 0) {
         $this->tableGateway->insert($data);
     } else {
         if ($this->get($id)) {
             $this->tableGateway->update($data, array('id' => $id));
         } else {
             throw new \Exception('User não existe');
         }
     }
 }
示例#2
0
 public function addUser(User $user)
 {
     $data = array('id' => $user->getId(), 'username' => $user->getUsername(), 'password' => $user->getPassword(), 'role_id' => $user->getRoleId(), 'create_date' => date("Y-m-d H:i:s"));
     $sql = new Sql($this->dbAdapter);
     $insert = $sql->insert('users');
     $insert->values($data);
     $selectString = $sql->getSqlStringForSqlObject($insert);
     $ret;
     try {
         $ret = $this->dbAdapter->query($selectString, Adapter::QUERY_MODE_EXECUTE);
     } catch (\Exception $e) {
         $ret = NULL;
     }
     return $ret;
 }