public function add_delete_cat() { $id = $_POST['id']; if ($id) { $category = new Category($id); $category->delete(); echo ''; return true; } $v = $_POST['val']; $category = new Category(); $category->setCategoryName($v); $id = $category->writeData(); $return['id'] = $id; $return['v'] = $v; echo json_encode($return); }