/** * @method POST */ function add() { // get an authuser $authUser = new AuthUser(); if (isset($authUser->UserUniqId)) { // check if authorized parse_str($this->request->data, $request); // parse request $friendlyId = $request['friendlyId']; $name = $request['name']; $pageTypeUniqId = $request['pageTypeUniqId']; $createdBy = $authUser->UserId; $pageType = PageType::GetByPageTypeUniqId($pageTypeUniqId); $category = Category::Add($friendlyId, $name, $pageType['PageTypeId'], $createdBy); // return a json response $response = new Tonic\Response(Tonic\Response::OK); $response->contentType = 'application/json'; $response->body = json_encode($category); return $response; } else { // unauthorized access return new Tonic\Response(Tonic\Response::UNAUTHORIZED); } }
function Add() { // Check the token if (!Kit::CheckToken()) { trigger_error(__('Sorry the form has expired. Please refresh.'), E_USER_ERROR); } $db =& $this->db; $user =& $this->user; $response = new ResponseManager(); $category = Kit::GetParam('category', _POST, _STRING); // Add the category $resObject = new Category($db); if (!$resObject->Add($category)) { trigger_error($resObject->GetErrorMessage(), E_USER_ERROR); } $response->SetFormSubmitResponse('New category added'); $response->Respond(); }