Esempio n. 1
0
<?php

session_start();
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/functions.php';
require_once __DIR__ . '/Todo.php';
// get todos
$todoApp = new \MyApp\Todo();
$todos = $todoApp->getAll();
?>

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="utf-8">
  <title>My Todos</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <div id="container">
    <h1>Todos</h1>
    <form action="">
      <input type="text" id="new_todo" placeholder="What needs to be done?">
    </form>
    <ul id="todos">
    	<?php 
foreach ($todos as $todo) {
    ?>
      		<li id="todo_<?php 
    echo h($todo->id);
    ?>
Esempio n. 2
0
<?php

session_start();
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/functions.php';
require_once __DIR__ . '/Todo.php';
$todoApp = new \MyApp\Todo();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    try {
        $res = $todoApp->post();
        header('Content-Type: application/json');
        echo json_encode($res);
        exit;
    } catch (Exception $e) {
        header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
        echo $e->getMessage();
        exit;
    }
}