+ 5

Trying to set up a php server, To-Dolist app with typescript. help please

Can someone explain to me what the code below is doing or how I'm supposed to use it. As I understand it, its like making an own server. Its for a school project, Im trying to build a To-Dolist with Typescript. <?php /* service.php */ date_default_timezone_set("Europe/Stockholm"); define('DB_HOST', 'localhost'); define('DB_NAME', 'todo'); define('DB_USER', 'root'); define('DB_PASS', 'segdeg'); require_once "db.inc"; require_once "todo.inc"; //require_once "DBBase.class"; $method = $_SERVER['REQUEST_METHOD']; if ($method == 'POST') { $json = file_get_contents('php://input'); $data = json_decode($json); $todoObj = new Todo(DB_HOST, DB_NAME, DB_USER, DB_PASS); if ($data->_action == "GetList") { $result = $todoObj->GetList(); print_r($result); } else if ($data->_action == "Get") { $result = $todoObj->Get($data); print_r($result); } else if ($data->_action == "Insert") { $result = $todoObj->Insert($data); print_r($result); } else if ($data->_action == "Update") { $result = $todoObj->Update($data); print_r($result); } else { die("wrong call"); } /* $class = $data->_group . 'Class'; require_once 'class/' . $data->_group . '.class'; $api = new $class(DB_SECURITY_HOST, DB_SECURITY_NAME, DB_SECURITY_USER, DB_SECURITY_PASS, $text); echo $api->Run($data); */ } else { die('NOT ALLOWED METHOD: ' . $method ); } ?>

9th Dec 2018, 8:41 PM
rashidk
rashidk - avatar
2 Respuestas
+ 1
its connecting to a database. then it checks to see if any posted data exists. it expects the posted data to be in JSON format, including a property called _action. it seems like action can be one of a few values insert, update, get. and then it runs the action. in order to run this you would need something to post the JSON. for just testing you could use a tool named Postman. but for making something worthwhile you would need a frontend . maybe some javascript ajax calls or Php curl calls. it just depends on what you want.
10th Dec 2018, 3:53 AM
John Anderson
John Anderson  - avatar
+ 5
John Anderson Thanks, I think I get it.
10th Dec 2018, 3:06 PM
rashidk
rashidk - avatar