/** * * @SWG\Api( * path="/admin/livenews", * description="Livenews related api", * produces="['application/json']", * @SWG\Operations( * @SWG\Operation( * method="POST", * summary="Create new livenews", * notes="Returns a livenews based on ID", * @SWG\Parameters( * @SWG\Parameter( * name="livenews json", * description="Livenews info", * paramType="body", * required=true, * type="string" * ) * ) * ) * ) * ) * @operationName("创建实时新闻") * @operationDescription("创建实时新闻") */ public function postAction() { $data = $this->request->getRawBody(); if (!$data) { throw new Exception\InvalidArgumentException('No data input'); } if (!($data = json_decode($data, true))) { throw new Exception\InvalidArgumentException('Data not able to decode as JSON'); } $form = new Forms\NewsForm(); $livenews = new Models\NewsManager(); $form->setModel($livenews); $form->addForm('text', 'Eva\\EvaLivenews\\Forms\\TextForm'); if (!$form->isFullValid($data)) { return $this->showInvalidMessagesAsJson($form); } try { $form->save('createNews'); $data = $livenews->dump(Models\NewsManager::$defaultDump); return $this->response->setJsonContent($data); } catch (\Exception $e) { return $this->showExceptionAsJson($e, $form->getModel()->getMessages()); } }