Exemplo n.º 1
0
 /**
  * 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()));
     }
 }