public function add() { if (!$this->application->request->isPost()) { throw new Exception('Method not allowed', 405); } if (!$this->isAllowed()) { throw new Exception('User not authorized', 401); } $postData = $this->application->request->getJsonRawBody(); $mg = MangaGenre::findFirst(array('conditions' => "name = :name:", 'bind' => array('name' => $postData->name))); if ($mg) { throw new Exception('MangaGenre already created', 409); } $mg = new MangaGenre(); $create = $mg->create(array('name' => $postData->name)); if (!$create) { throw new Exception('MangaGenre not created', 409); } return array('code' => 201, 'content' => $mg->toArray()); }