/** * For JS AJAX validation - validates a property of Room object. * @return JSON status=ok|error,message={string} */ public function validateJSONAction() { try { $propName = $this->params()->fromPost('propName'); if (!in_array($propName, Room::propertyNames())) { throw new \Exception('Wrong property provided.'); } $value = $this->params()->fromPost('value'); if (!$propName || !$value) { throw new \Exception('No property and/or value given.'); } $form = new RoomForm(); $form->setInputFilter($this->getServiceLocator()->get('room')->getInputFilter()); $form->setData(array($propName => $value))->isValid(); $elements = $form->getElements(); $element = $elements[$propName]; if (count($element->getMessages())) { return $this->myJsonModel(array('status' => 'error', 'message' => $element->getMessages())); } else { return $this->myJsonModel(array('status' => 'ok', 'message' => '')); } } catch (\Exception $e) { return $this->myJsonModel(array('status' => 'error', 'message' => $e->getMessage())); } }
public function update($id, $data) { $data['id'] = $id; $room = $this->getRoomTable()->getRoom($id); $form = new RoomForm(); $form->setHydrator(new \Zend\Stdlib\Hydrator\ObjectProperty()); $form->bind($room); //$form->setInputFilter($room->getInputFilter()); $form->setData($data); if ($form->isValid()) { $id = $this->getRoomTable()->saveRoom($form->getData(), $data['id']); } return $this->get($id); }