PHP
  Home arrow PHP arrow Page 2 - Defining the Core Structure of a PHP Blogger
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Defining the Core Structure of a PHP Blogger
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 11
    2006-11-21


    Table of Contents:
  • Defining the Core Structure of a PHP Blogger
  • Defining the blogger's core structure
  • Defining the insertBlog() method
  • Defining the updateBlog() method
  • Defining the deleteBlog() method

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Defining the Core Structure of a PHP Blogger - Defining the blogger's core structure
    ( Page 2 of 5 )

    Naturally, a good place to start building the blogger system with PHP 5 consists of defining its basic structure so it will be easier for you to understand how each module of the application fits together with each other module.

    This being said, the blogger in question will be created by using only one PHP class. It will be responsible for performing the insertion, update and deletion of blog entries respectively, in conjunction with displaying the entire list of blogs and the corresponding online forms, handy for posting and updating a particular entry.

    Considering all the prerequisites that I established before, here is the initial definition for the new "BlogProcessor" class. Take a look at its signature, please:

    // define 'BlogProcessor' class
    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']){
                                       // code for displaying edit page goes here                     

                            }
                            else{
                                       // insert new blog
                                       if($this->blogData['insertblog']){
                                                   $this->insertBlog();
                                       }
                                       // update blog
                                       elseif($this->blogData['updateblog']){
                                                   $this->updateBlog();
                                       }
                                       // delete blog
                                       elseif($this->blogData['deleteblog']){
                                                   $this->deleteBlog();       
                                       }
                            }
                            // code for displaying main page goes here
                }  
    }

    As illustrated above, the skeleton of the new "BlogProcessor" class is very simple to grasp (at least for now). Basically, I split up the structure of the class into two main methods. The first one is obviously the constructor that performs a few useful initialization tasks, while the second one, called "displayBlogger()," is tasked with inserting, updating and deleting blog entries, as well as displaying the corresponding forms for handling blog-related data.

    However, for the moment you should ignore all the processes concerning the display of blog entries, and focus your attention on the signature of the methods listed above. As you can see, the constructor accepts an object of type "MySQL" as its unique input parameter, which comes in useful for database connectivity inside the blog processor class, running queries and processing MySQL result sets.

    Don't worry for the moment about this MySQL class, because at the end of the series you'll be provided with all the classes required to get the blogger working. However, at least for now, you'll have to settle for with studying the methods declared before.

    Returning to the definition of the "displayBlogger()" method that belongs to the blog processor class, you'll realize that it contains three additional private methods. These are called "insertBlog()", "updateBlog()" and "deleteBlog()" respectively, and they perform well-differentiated tasks, like inserting new entries, and updating/deleting existing ones. So far, nothing unexpected, right?

    In addition, you'll notice the use of the "$this->blogData" property as a flag for executing the different operations associated with distinct entries. In this case, I decided to use the superglobal $_POST array to do this, but this condition can be easily modified and utilize instead some variables passed in via the GET method.

    All right, I believe that all the explanations that I offered before would be rather incomplete if I don't show you a few screen shots that illustrate the look and feel that I plan to give to the blog system. Therefore, here are the corresponding images:

    As you can see, the three pictures included above demonstrate in a clear fashion the different screens that will be presented to the user to perform the insertion of entries, as well as the update and deletion of them. In addition, I showed you the panel that displays the complete list of blogs, which means that at this point, you should have an accurate idea of how the blogger system will look at first glance.

    Well, having defined the general structure of the corresponding "BlogProcessor" class, it's time to move on and start coding each one of the private methods that were declared previously to perform the insertion, update and deletion of blog entries. Sounds interesting, doesn't it?

    To learn how these important methods will be defined, keep reading.



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT