diff --git a/classes/Basic_Form.php b/classes/Basic_Form.php index aa7e8f07..751d5993 100644 --- a/classes/Basic_Form.php +++ b/classes/Basic_Form.php @@ -11,61 +11,61 @@ class Basic_Form { - public function open($class, $method='post') + public function open($class='form-horizontal', $method='post') { - - ?>
+ +
+ ?> +
-
+
+ ?> +
-
+
+ ?> +
-
+ + + + + 'Starter Application']; - Basic::view('home', $data); - + Basic::view('home', compact('page_title')); } } \ No newline at end of file diff --git a/controllers/PostController.php b/controllers/PostController.php index b24260f5..eaf460bd 100644 --- a/controllers/PostController.php +++ b/controllers/PostController.php @@ -1,11 +1,5 @@ view( Basic::segment(3) ); if ($row) { - $page_title = 'View Post'; - $data = compact('row', 'page_title'); - Basic::view('post_view', $data); - + Basic::view('post_view', compact('page_title', 'row')); } else { - $error_message = 'The Post ID does not exist.'; $page_title = 'Error in Post ID'; - $data = compact('error_message', 'page_title'); - Basic::view('error', $data); - + Basic::view('error', compact('page_title', 'error_message')); } } public function add() { - if ($this->isPostAdd()) { - $post = new PostModel; $new_id = $post->add(); header('Location: ' . BASE_URL . 'post/view/' . $new_id); exit(); - } - $data = ['page_title' => 'Add a Post']; - Basic::view('post_add', $data); + $page_title = 'Add a Post'; + Basic::view('post_add', compact('page_title')); } public function edit() { - $post = new PostModel; if ($this->isPostEdit()) { - $post->edit( Basic::segment(3) ); header('Location: ' . BASE_URL . 'post/view/' . Basic::segment(3)); exit(); - } $row = $post->view( Basic::segment(3) ); if ($row) { - $page_title = 'Edit Post'; - $data = compact('row', 'page_title'); - Basic::view('post_edit', $data); - + Basic::view('post_edit', compact('page_title', 'row')); } else { - $error_message = "The Post ID does not exist."; $page_title = 'Error in Post ID'; - $data = compact('error_message', 'page_title'); - Basic::view('error', $data); - + Basic::view('error', compact('page_title', 'error_message')); } - } public function delete() { - $post = new PostModel; $post->delete( Basic::segment(3) ); - } private function isPostAdd() { - if ( isset($_POST['submit-post']) && isset($_POST['csrf-token']) && isset($_SESSION['csrf-token']) && $_POST['csrf-token'] == $_SESSION['csrf-token'] ) return TRUE; - } private function isPostEdit() { - if ( isset($_POST['edit-post']) && isset($_POST['csrf-token']) && isset($_SESSION['csrf-token']) && $_POST['csrf-token'] == $_SESSION['csrf-token'] ) return TRUE; - } private function isPostDelete() { - if ( isset($_POST['delete-post']) && isset($_POST['csrf-token']) && isset($_SESSION['csrf-token']) && $_POST['csrf-token'] == $_SESSION['csrf-token'] ) return TRUE; - } } \ No newline at end of file diff --git a/controllers/RequestController.php b/controllers/RequestController.php index 78932391..dfb961cd 100644 --- a/controllers/RequestController.php +++ b/controllers/RequestController.php @@ -1,11 +1,5 @@ $_POST['patient-name']]; // $data_input as an array $output = Basic::api_call('POST', BASE_URL . 'api/request', $input, 'Peter', 12345); - $data = compact('page_title', 'output'); - Basic::view('request', $data); - + Basic::view('request', compact('page_title', 'output')); } else { + $page_title = 'API Request'; - $data = ['page_title' => 'API Request']; - Basic::view('request', $data); - + Basic::view('request', compact('page_title')); } } diff --git a/controllers/SampleController.php b/controllers/SampleController.php index 79a88976..2fd53173 100644 --- a/controllers/SampleController.php +++ b/controllers/SampleController.php @@ -1,11 +1,5 @@
diff --git a/views/post_add.php b/views/post_add.php index 996876c0..f656f90c 100644 --- a/views/post_add.php +++ b/views/post_add.php @@ -10,10 +10,10 @@

Add Post

open('form-horizontal'); + $form->open(); $form->input('text', 'title', 'Title'); $form->textArea('content', 'Content'); - $form->button('submit-post', 'Submit', 'btn btn-default'); + $form->button('submit-post', 'Submit'); $form->csrfToken(); $form->close(); ?> diff --git a/views/post_edit.php b/views/post_edit.php index e319a556..d7d5499d 100644 --- a/views/post_edit.php +++ b/views/post_edit.php @@ -9,14 +9,14 @@

Edit Post

open('form-horizontal'); + $form->open(); $form->input('text', 'title', 'Title', $post_title); $form->textArea('content', 'Content', $post_content); - $form->button('edit-post', 'Edit', 'btn btn-default'); + $form->button('edit-post', 'Edit'); $form->csrfToken(); $form->close(); ?> diff --git a/views/post_view.php b/views/post_view.php index b9fb7ddb..c61d0f5f 100644 --- a/views/post_view.php +++ b/views/post_view.php @@ -15,7 +15,7 @@ open('form-inline'); - $form->button('goto-edit', 'Edit', 'btn btn-default'); + $form->button('goto-edit', 'Edit'); $form->button('delete-post', 'Delete', 'btn btn-warning'); $form->csrfToken(); $form->close();