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; } }
public function loginAction() { if ($this->authenticationService->hasIdentity()) { return $this->redirect()->toRoute('home'); } $this->layout('layout/layout-blank'); $resultModel = new JsonResultModel(); if ($this->getRequest()->isPost()) { $jsonData = $this->getRequest()->getPost('login'); $data = Json::decode($jsonData, Json::TYPE_ARRAY); // If you used another name for the authentication service, change it here $adapter = $this->authenticationService->getAdapter(); $adapter->setIdentityValue($data['username']); $adapter->setCredentialValue($data['password']); $authResult = $this->authenticationService->authenticate(); //@todo remember me if ($authResult->isValid()) { if ($data['rememberMe']) { $this->authenticationService->getStorage()->getManager()->rememberMe(36000); } return $resultModel; } else { $resultModel->addErrors('password', '登录名或密码错误'); return $resultModel; } } }