public function action_edit($id = null) { if (!isset($_SESSION['user_id'])) { return Response::redirect('login'); } is_null($id) and Response::redirect('Entry'); if (!($entry = Model_Entry::find($id))) { Response::redirect('Entry'); } $val = Model_Entry::validate('edit'); if ($val->run()) { $entry->title = Input::post('title'); $entry->content = Input::post('content'); if ($entry->save()) { Response::redirect('entry'); } } else { if (Input::method() == 'POST') { $entry->title = $val->validated('title'); $entry->content = $val->validated('content'); } $this->template->set_global('entry', $entry, false); } $this->template->title = "Entries"; $this->template->content = View::forge('entry/edit'); }