/** * レコード編集 */ public function edit($id = null) { if (!$id && empty($this->data)) { $this->Session->setFlash(__('不正なIDです', true)); $this->redirect(array('action' => 'index')); } // 値一覧のセット $this->set('valueLists', $this->Todo->valueLists); if (!empty($this->data)) { if (empty($this->data['Todo']['id'])) { $this->data['Todo']['id'] = $id; } if ($this->Todo->save($this->data)) { $this->Session->setFlash(__('TODOを保存しました', true)); $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__('TODOの保存に失敗しました', true)); } } if (empty($this->data)) { $this->data = $this->Todo->read(null, $id); } }
<?php require_once "api/database.php"; require_once "api/todo.php"; $todo = new Todo(); switch ($_SERVER['REQUEST_METHOD']) { case 'GET': $params = str_replace('/', '', $_SERVER['QUERY_STRING']); parse_str($params, $params); $todo->read($params); break; case 'PUT': parse_str(file_get_contents('php://input'), $p_data); $object = json_decode(stripslashes($p_data['model']), true); $todo->update($object); break; case 'POST': $object = json_decode(stripslashes($_POST['model']), true); $todo->create($object); break; case 'DELETE': $id = (int) str_replace('/', '', $_SERVER['QUERY_STRING']); $todo->delete($id); break; }
Todo::mark_complete($_GET['id']); refresh(); } } ?> <!DOCTYPE html> <head> <title>Simple Todo</title> <link rel="stylesheet" href="static/styles.css"> </head> <body> <?php if (isset($update_mode)) { if ($update_mode) { $data = Todo::read($_GET['item_id']); ?> <center><h4>Update a todo item.</h4></center> <hr/> <form method="post" action="." name="update"> <input type="hidden" name="id" value="<?php echo $_GET['item_id']; ?> "> <input type="text" name="title" value="<?php if ($data) { echo $data['title']; } ?> "> </form>