From a99ed12dc9a0d7d02721fa6b781b47116b976e3b Mon Sep 17 00:00:00 2001 From: Dylan Lloyd Date: Sat, 24 Mar 2012 14:18:12 -0400 Subject: [PATCH] page layout now fully separated m/v/c --- model/note.php | 18 ++++++++---------- model/page.php | 29 ++++++++++------------------- view/page.php | 21 +++++++++++++++++++-- 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/model/note.php b/model/note.php index 01338be..d5ab563 100644 --- a/model/note.php +++ b/model/note.php @@ -12,6 +12,7 @@ class note extends model { public $day_posted; public $text; public $number_of_comments; + public $comments; public function __construct() { parent::__construct(); @@ -97,22 +98,19 @@ class note extends model { } public function display_comments() { - echo "
"; + // should be called like $note->comment[0]['author'] $sql= "SELECT date_posted, author, text FROM comments WHERE note = ? ORDER BY date_posted DESC"; $result = $this->query($sql, 'd', $this->id); + $i = 0; foreach ($result as $row => $entry) { - $date_posted = $entry['date_posted']; - $author = $entry['author']; - $text = htmlspecialchars($entry['text']); - $head = "

" . htmlspecialchars($author) . "

"; - echo "
"; - echo $head; - echo $text; - echo "
"; + $this->comment[$i]['date_posted'] = $entry['date_posted']; + $this->comment[$i]['author'] = $entry['author']; + $this->comment[$i]['text'] = htmlspecialchars($entry['text']); + $this->comment[$i]['head'] = "

" . htmlspecialchars($author) . "

"; + $i++; } - echo "
"; } public function display_comment_form() { diff --git a/model/page.php b/model/page.php index fe7d0a6..b4c5577 100644 --- a/model/page.php +++ b/model/page.php @@ -6,10 +6,12 @@ class page extends model { public $offset = 0; public $notes_per_page = 4; public $number_of_pages = 1; + public $notes = array(); public function __construct() { parent::__construct(); $this->page_offset(); + $this->fetch_notes(); } private function page_offset() { @@ -35,8 +37,7 @@ class page extends model { require_once("view/page.php"); } - public function display_notes() { - echo "
"; + protected function fetch_notes() { $sql = "SELECT date_posted, title, url, text FROM notes ORDER BY date_posted DESC LIMIT ?, ?"; @@ -44,24 +45,14 @@ class page extends model { $this->offset, $this->notes_per_page); foreach ($result as $row => $entry) { - $title = $entry['title']; - $url = '/note/' . $entry['url']; - $date_posted = explode("-", $entry['date_posted']); - $year_posted = $date_posted[0]; - $month_posted = $date_posted[1]; - $datetime_posted = explode(' ', $date_posted[2]); - $day_posted = $datetime_posted[0]; - $text = $entry['text']; - echo << -

- $year_posted/$month_posted/$day_posted/$title -

- $text -
-END_NOTE; + $entry['url'] = '/note/' . $entry['url']; + $date_posted = explode("-", $entry['date_posted']); + $entry['year_posted'] = $date_posted[0]; + $entry['month_posted'] = $date_posted[1]; + $entry['datetime_posted'] = explode(' ', $date_posted[2]); + $entry['day_posted'] = $entry['date_posted'][0]; + $this->notes[$row] = $entry; } - echo ""; } } diff --git a/view/page.php b/view/page.php index 2829668..72d5edd 100644 --- a/view/page.php +++ b/view/page.php @@ -35,8 +35,25 @@
-
- display_notes() ?> +
+
+ notes as $note) { + echo "
"; + echo "

"; + echo ""; + echo $note['year_posted'] . "/"; + echo $note['month_posted'] . "/"; + echo $note['day_posted'] . "/"; + echo ""; + echo ""; + echo $note['title']; + echo ""; + echo "

"; + echo $note['text']; + } + ?> +