Esempio n. 1
0
 public function createCustomerAction()
 {
     $resultModel = new JsonResultModel();
     if ($this->getRequest()->isPost()) {
         try {
             $jsonData = $this->params()->fromPost('customer');
             $customer = new Customer(Json::decode($jsonData, Json::TYPE_ARRAY));
             $customer->setCreateTime(new \DateTime());
             //@todo 这一行抛出异常被捕获处理后,会不会执行下一行??
             $this->customerService->create($customer);
         } catch (ValidationException $e) {
             $resultModel->setErrors($e->getValidationError());
             return $resultModel;
         } catch (\Exception $e) {
             $resultModel->addErrors('undefined', $e->getMessage());
             return $resultModel;
         }
         return $resultModel;
     }
 }