src/User/Controller/RestController.php
public function update($id, $data)
	{
		$this->getResponse()
			->setStatusCode(Response::STATUS_CODE_201);
		
		$request = $this->getRequest();
		$content = $request->getContent();
		$content = !empty($content) ? Json::decode($content, Json::TYPE_ARRAY) : array();
		$post = array_merge_recursive(
			$request->getPost()->toArray(),
			$content
		);
		$post['id'] = $id;
		$action = isset($post['action']) ? strtolower($post['action']) : strtolower($this->params()->fromQuery('action'));
		$userService = $this->getServiceLocator()->get('user.service.user');
		
		switch($action) {
			case 'activation':    	
				try {
		    		$user = $userService->activate($id, false); // Second arg for not to force activation of banned users
		    		
		    		// we need to check the status
		    		if($user->getState() != UserEntity::USER_STATE_ACTIVE ) {
		    			throw new \Exception('Questo utente non può essere attivato, per ulteriori info contattaci su info@neobazaar.com');
		    		}
		    		
		    		$data = array(
						'status' => 'success',
						'message' => 'Utente attivato con successo, abbiamo inviato la password al tuo indirizzo email.'
		    		);
		    	} catch(\Exception $e) {
		    		$this->getResponse()
		    			->setStatusCode(Response::STATUS_CODE_500);
		    		$data = array(
						'status' => 'danger',
						'message' => $e->getMessage()
		    		);
		    	}
				break;
			case 'passwordrecovered':    	
				try {
		    		$user = $userService->passwordRecovered($id);
		    		
		    		$data = array(
						'status' => 'success',
						'message' => 'Operazione effettuata con successo, abbiamo inviato la password al tuo indirizzo email, potrai modificarla accedendo al tuo account.'
		    		);
		    	} catch(\Exception $e) {
		    		$this->getResponse()
		    			->setStatusCode(Response::STATUS_CODE_500);
		    		$data = array(
						'status' => 'danger',
						'message' => $e->getMessage()
		    		);
		    	}
				break;
			case 'disableenable':
				try {
					$user = $userService->enableDisable($id);		
					$returnData = array(
						'status' => 'success',
						'message' => 'Operazione effettuata con successo'
					);
				} catch(\Exception $e) {
					$this->getResponse()
						->setStatusCode(Response::STATUS_CODE_500);
					$returnData = array(
						'status' => 'danger',
						'message' => $e->getMessage()
					);
				}
				break;
			case 'banunban':
				try {
					$user = $userService->banUnban($id);		
					$returnData = array(
						'status' => 'success',
						'message' => 'Operazione effettuata con successo'
					);
				} catch(\Exception $e) {
					$this->getResponse()
						->setStatusCode(Response::STATUS_CODE_500);
					$returnData = array(
						'status' => 'danger',
						'message' => $e->getMessage()
					);
				}
				break;
			case 'checkloggedin':
				break;
			case 'logout':
				break;
			case 'login':
				break;
			case 'update':
			default:
				try {
					$userService->save($post, false); // do not trigger events
					$data = array(
						'status' => 'success',
						'message' => 'Operazione eseguita con successo'
					);
				} catch(\Exception $e) {
					$this->getResponse()
						->setStatusCode(Response::STATUS_CODE_500);
					$data = @unserialize($e->getMessage());
					
					if(!is_array($data)) {
						$data = array(
							'status' => 'danger',
							'message' => $e->getMessage()
						);
					}
				}
				break;
		}
		
		return new JsonModel($data);
	}
public function update($id, $data)
	{
		$this->getResponse()
			->setStatusCode(Response::STATUS_CODE_201);
		
		$request = $this->getRequest();
		$content = $request->getContent();
		$content = !empty($content) ? Json::decode($content, Json::TYPE_ARRAY) : array();
		$post = array_merge_recursive(
			$request->getPost()->toArray(),
			$content
		);
		$post['id'] = $id;
		$action = isset($post['action']) ? strtolower($post['action']) : strtolower($this->params()->fromQuery('action'));
		$userService = $this->getServiceLocator()->get('user.service.user');
		
		switch($action) {
			case 'activation':    	
				try {
		    		$user = $userService->activate($id, false); // Second arg for not to force activation of banned users
		    		
		    		// we need to check the status
		    		if($user->getState() != UserEntity::USER_STATE_ACTIVE ) {
		    			throw new \Exception('Questo utente non può essere attivato, per ulteriori info contattaci su info@neobazaar.com');
		    		}
		    		
		    		$data = array(
						'status' => 'success',
						'message' => 'Utente attivato con successo, abbiamo inviato la password al tuo indirizzo email.'
		    		);
		    	} catch(\Exception $e) {
		    		$this->getResponse()
		    			->setStatusCode(Response::STATUS_CODE_500);
		    		$data = array(
						'status' => 'danger',
						'message' => $e->getMessage()
		    		);
		    	}
				break;
			case 'passwordrecovered':    	
				try {
		    		$user = $userService->passwordRecovered($id);
		    		
		    		$data = array(
						'status' => 'success',
						'message' => 'Operazione effettuata con successo, abbiamo inviato la password al tuo indirizzo email, potrai modificarla accedendo al tuo account.'
		    		);
		    	} catch(\Exception $e) {
		    		$this->getResponse()
		    			->setStatusCode(Response::STATUS_CODE_500);
		    		$data = array(
						'status' => 'danger',
						'message' => $e->getMessage()
		    		);
		    	}
				break;
			case 'disableenable':
				try {
					$user = $userService->enableDisable($id);		
					$returnData = array(
						'status' => 'success',
						'message' => 'Operazione effettuata con successo'
					);
				} catch(\Exception $e) {
					$this->getResponse()
						->setStatusCode(Response::STATUS_CODE_500);
					$returnData = array(
						'status' => 'danger',
						'message' => $e->getMessage()
					);
				}
				break;
			case 'banunban':
				try {
					$user = $userService->banUnban($id);		
					$returnData = array(
						'status' => 'success',
						'message' => 'Operazione effettuata con successo'
					);
				} catch(\Exception $e) {
					$this->getResponse()
						->setStatusCode(Response::STATUS_CODE_500);
					$returnData = array(
						'status' => 'danger',
						'message' => $e->getMessage()
					);
				}
				break;
			case 'checkloggedin':
				break;
			case 'logout':
				break;
			case 'login':
				break;
			case 'update':
			default:
				try {
					$userService->save($post, false); // do not trigger events
					$data = array(
						'status' => 'success',
						'message' => 'Operazione eseguita con successo'
					);
				} catch(\Exception $e) {
					$this->getResponse()
						->setStatusCode(Response::STATUS_CODE_500);
					$data = @unserialize($e->getMessage());
					
					if(!is_array($data)) {
						$data = array(
							'status' => 'danger',
							'message' => $e->getMessage()
						);
					}
				}
				break;
		}
		
		return new JsonModel($data);
	}
Respond to HTTP PUT method with data, with :id
@see \Zend\Mvc\Controller\AbstractRestfulController::update()
@todo Make a service like ZfcUser