As I usually do in each of my articles on web development, before I leap forward and start giving the final touches to the blog application, I’d like to show you briefly how the “BlogProcessor” class looked originally. This will refresh your memory before we proceed. Here is the full source code that corresponds to the mentioned class, in accordance with the signature defined in the previous article. Please, have a look at it: class BlogProcessor{ private $mysql; private $blogData; public function __construct(MySQL $mysql){ $this->mysql=$mysql; $this->blogData=$_POST; } // display blog system public function displayBlogger(){ // edit blog if($this->blogData['editblog']){ // display edit page return $this->displayEditPage } else{ // insert new blog if($this->blogData $this->insertBlog(); } // update blog elseif($this->blogData $this->updateBlog } // delete blog elseif($this->blogData $this->deleteBlog } } // display main page return $this->displayMainPage(); } // insert new blog private function insertBlog(){ $title=$this->blogData['title']; $author=$this->blogData['author']; $content=$this->blogData['content']; $this->mysql->query("INSERT INTO blogs header('Location:'.$_SERVER } // update blog private function updateBlog(){ $id=$this->blogData['id']; $title=$this->blogData['title']; $author=$this->blogData['author']; $content=$this->blogData['content']; $this->mysql->query("UPDATE blogs SET header('Location:'.$_SERVER['PHP_SELF']); } // delete blog private function deleteBlog(){ $id=$this->blogData['id']; $title=$this->blogData['title']; $author=$this->blogData['author']; $content=$this->blogData['content']; $this->mysql->query("DELETE FROM blogs header('Location:'.$_SERVER['PHP_SELF']); } // display all the blogs private function displayBlogs(){ $result=$this->mysql->query("SELECT * $output=''; while($row=$result->fetchRow()){ $content=nl2br($row $output.=<<<EOD <div class="blog"> <h2>$row[title]</h2> <h3> Author: $row[author]<h3> <h3> Posted: $row[date]</h3> <p>$content</p> <form action="$_SERVER[PHP_SELF]" method="post"> <input type="submit" value="Edit Blog" name="editblog" /> <input type="submit" value="Delete Blog" name="deleteblog" /> <input type="hidden" value="$row[id]" name="id" /> </form> </div> EOD; } return $output; } // display insertion form private function displayInsertForm(){ $output=<<<EOD <div class="dataform"> <h2>Insert New Blog</h2> <form action="$_SERVER[PHP_SELF]" method="post" id="insertform"> <p>Title:</p><p><input type="text" name="title" <p>Author:</p><p><input type="text" name="author" <p>Type your content below</p><p><textarea <p><input type="submit" name="insertblog" value="Insert </form> </div> EOD; return $output; } // display update form private function displayUpdateForm(){ $id=$this->blogData['id']; $result=$this->mysql->query("SELECT * if($result->countRows()>0){ $row=$result->fetchRow(); $output=<<<EOD <div class="dataform"> <h2>Update Blog</h2> <form action="$_SERVER[PHP_SELF]" method="post" id="updateform"> <p>Title:</p><p><input type="text" name="title" value="$row <p>Author:</p><p><input type="text" name="author" value="$row <p>Update your content below</p><p><textarea name="content">$row <p><input type="submit" name="updateblog" value="Update <input type="hidden" value="$id" name="id" /> </form> </div> EOD; return $output; } } // display page header private function displayHeader(){ $output=<<<EOD <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso- <title>Blogger System</title> <link href="styles.css" rel="stylesheet" type="text/css" <script language="javascript" src="valfunctions.js"></script> </head> <body> <h1>PHP-BASED BLOG SYSTEM</h1> EOD; return $output; } // display page footer private function displayFooter(){ return '</body></html>'; } // display main page private function displayMainPage(){ return $this->displayHeader().$this- } // display edit page private function displayEditPage(){ return $this->displayHeader().$this- } } As you’ll probably remember at this point, the above blog processor class has been provided with all the required methods for inserting, updating and deleting blog entries, in addition to displaying these entries in the browser. However, you’ll notice this class also accepts an object of type “MySQL,” which is very convenient for performing all the database-related operations inside the context of the class. Now that you hopefully recalled how the “BlogProcessor” class was defined originally, you’re surely wondering…what’s the next step? Well, obviously I need to show you the respective signature of the “MySQL” class, which is aggregated by the blog processor. In the following section, I’ll be doing exactly that. Want to learn how this MySQL wrapping class really looks? Be a bit more patient and keep reading.
blog comments powered by Disqus |
|
|
|
|
|
|
|