Exemplo n.º 1
0
 public function addAction()
 {
     $response = array();
     $service = $this->getPostService();
     $request = $this->getRequest();
     $postForm = new PostForm();
     $userModel = new Post();
     $postForm->setInputFilter($userModel->inputFilter());
     $postForm->setData($request->getPost());
     if ($postForm->isValid()) {
         try {
             $userModel->exchangeArray($postForm->getData());
             $model = $service->save($userModel);
             $response = array('status' => true, 'data' => $model, 'message' => '');
         } catch (\Exception $e) {
             $response = array('status' => false, 'exception' => 'SERVICE_ERROR', 'data' => null, 'message' => $e->getMessage());
         }
     } else {
         $response = array('status' => false, 'exception' => 'INVALID_DATA', 'data' => $postForm->getMessages(), 'message' => 'Please Provide valid data');
     }
     return new JsonModel($response);
 }