Object Oriented Programming PHP Tutorial
Object Oriented Programming: The Journal of an Idiot
Bruce Gust 

  Here's my dilemma and my goal: I've got to build an application that would normally be "cake and ice cream" if I allowed myself the luxury of building it using a Procedural approach. But I'm determined to build it using OOP simply because it's a healthy thing to stay current on contemporary models and frameworks. I'm going to document things as I attempt to get my brain around all this and then chronicle how I attempted to implement those things as I built my application. Buckle up! Here we go! Contents: I) The Basics II) What's a Class?   A) What's a Property?     1) Visibility   B) Using Construct     1) Initializing     2) What is "$this->"?   C) Constants III) Some Practical Application   A) Writing a CSV File - lots of great functionality here as far as how to write a CSV file in the context of an OOP approach  B) Parsing a JSON FileIV) Model, View, Controller   A) Intro   B) The "Controller"   C) The "Model"   D) The "View" BTW: In some instances, I've documented the code using a little "code box," but in other instances, where the situation seemed to warrant it, I wrote it out and incorporated color coded some comments in green to make it stand out from the code which is written in blue. FYI: Here are some great sites that provide some wonderful background and theory: w3resource.com PHPro CSS Tutorial (selectors and more...) Also, for the sake of being able to document code, click here to access the "code machine." All you'll do is enter your raw code and the script will then enter the appropriate CSS tags so you can then display it like what you see here. Here's the way I'm looking at OOP: With a Procedural approach, you have to stick the key in the ignition and start up the car every time you want to give your user a chance to access information in a database. With OOP, you start the car one time. You do all the heavy lifting up front and then it's just a matter of grabbing information that's already been retrieved and / or processed. Kind of cool...
Before we get into Functions and Classes and other definitions, there's a very cool "bottom line" that's worth rehearsing before we get into all this. You can write funtions and still not be doing OOP. "So what's the difference between writing functions and OOP" you ask. Simply put, OOP is the next step in "grouping" blocks of code together in order to facilitate more proficiency. For example, you have straight ahead Procedural code where I'm coding a task every time I need it in the context of my page like this: <?php echo "hello"; ?> ...or you could write it as a function like this: <?php //you write this one time at the top of your page function say_something(); echo "hello"; ?> <?php say_something(); ?> The advantage of doing things using Functions is that if you had to go back and instead of saying "hello," you wanted to say "wuddup," depending on the size of your app, you've got a lot of work ahead of you. On the other hand, if you used a Functional approach, you just have to change the one line in your function from "hello" to "wuddup" and you're done. Do you see where we're going with all this? Instead of writing a task every time you want to use it, you write it one time and in so doing you "group" your tasks together in one location rather than have them scattered throughout your app. With OOP, you take the concept of "grouping" a step further in that you're actually grouping your Functions into things called Classes. Now you're looking at something like this: class say_something { public $hello; public $wuddup; public function __construct(){ $this->hello="hello"; $this->wuddup="wuddup?"; } public function speak() { echo $this->hello.' '.$this->wuddup; } } So, now you've got even more functionality in that you can accomplish several things in the context of a Class where you've got multiple functions happening simultaneously. Again, if you had to write "hello" and "wuddup" in the context of a single line of PHP code throughout your app, you're stuck if you've got to make a global change. With OOP, now you have a place where you're doing all your heavy lifting in one place. You make your alteration in that one centralized location and you've impacted your entire app without having to go through things line by line. Here we go...
Some basic elements that you need to be familar with: Depending on how you're wired mentally, my illustrations may or may not resonate with you and I've seen several different explanations of what a "class" is, but this is the illustration I landed on that allowed the "class" to make sense to me. When you create a blank spreadsheet, you're creating a class. You've got columns (aka "properties") and you've got rows, but you don't refer to them as columns and rows. Rather, you've got some other terminology to consider. We'll get into this more later, but no doubt you've heard the term "functions." The difference between a function and a class is that with a class you typically So, in that regard you have something where a spreadsheet is a very apt illustration in that you can envision how certain "cells" can have functions built into them. OK, onward...   A) What's a Property?
snare kick hihat
The column names are referred to as "properties" but you don't have any info. You'll populate the columns / rows in a little bit with some actual information, but as far as what a basic property within a Class is, think of a blank spreadsheet with column names like what you see to the right. As far as the syntax is concerned, that would look like this: class MyDrumset { public $snare; public $kick; public $hihat; } In this example, you've got a Class called MyDrumset and you have three properties (column headings); $snare, $kick and $hihat.         1) Visibility When you see "public," don't freak. You've got three classifications of properties within a class and they are as follows: Bottom line: How you define your properties will determine the extent to which they're available throughout your app. For now, we're calling everything "public." It's worth it to pause and consider what these three types of properties look like. The illustration to the right shows you how these types of properties can and should be used and how their definition plays out practically. Imagine we've got a function that is going to upload a CSV file. At the top you've got something like this: Class MyCSV { public $csv; protected $header; protected $data; The three properties that are established at the beginning consist of two "protected" properties and it makes sense. Given the fact that "$header" and "$data" are common terms and things that could easily get confused with other elements, you want to ensure that the wires aren't going to cross so you make them "protected."
The "official" term that applies the different types of properties is "visibility," and you can find more info about that in the PHP Manual. It has a great example on how "public, protected and private" variables can be accessed in the context of a page based on the visibility they've been assigned.
  B) Using the Construct (_constructor) - the "rows..." Now, let's add some "rows" to our "class." Remember, all we've got right now is a blank spreadsheet with column names. Now we're going to add some "rows." The cells are blank in this example, although you could hardcode some values into them. In this instance, we're just establishing some scaffolding. This gets back to what was stated earlier as far as the difference between Classes and Functions being that with a Class you have both data and functions. While functions are machines that are manipulating data, a Class has the capacity to manipulate data as well as store data within itself. Again, think of a spreadsheet. Right now, we've got three column headings but we have no rows beneath them. Now watch... Here's the syntax: class MyDrumset { public $snare; public $kick; public $hihat; public function __construct($three, $blind, $mice) (This is important! The "construct" word is prefaced with two underscores (__), not one!) { $this->snare=$three; $this->kick=$blind; $this->hihat=$mice; } }
snare kick hihat
     
...and if your refer to the little table to the right, you can see what this looks like using our "spreadsheet" example:         1) Initializing Using the constructor and establishing digital placeholders that coincide with each of our three properties is called "initializing." It's not a term limited to OOP or Classes, but it's the term used here nevertheless.
The Construct function is more important than you might imagine. At one point, I was crafting a Class and positioning Functions in a way where I was assuming they were talking to one another. In other words, I used a Function to define a variable based on a posted piece of data coming from a form. I then moved on in my logic to the next function where I took this newly declared variable and proceeded to write some code around it only to find out after the fact that Functions don't really talk to one another, even when housed in the same Class. If you've got more than one Function sharing a piece of data, define that using your Construct function. Like this:
  1. class StoreCSV {
  2.  public $csv;
  3.  protected $data;
  4.  public function __construct() { //right here is where I'm talking about
  5.   if(empty($_POST['csv_name']))
  6.   {
  7.   print "there's no CSV to look at";
  8.   }
  9.   else
  10.   {
  11.   $this->csv=$_POST['csv_name'];
  12.   }
  13.  }
  14.  public function loadCSV()
  15.  {
  16.  global $mysqli;
  17.  $this->csv_file_name="csv/$this->csv"; //$this->csv is "seen" by loadCSV because it has been correctly defined by the construct function on line 5
  18.  //return $this->csv_file_name;
  19.  var_dump($this->csv_file_name);
  20.  $handle=fopen($this->csv_file_name, "r");
  21.  }
  22. }
When you look at line 5, that one little construct element is what made all the difference. Previously I had written a function where I defined the variable and then expected my function on line 15 to recognize $this->csv and it didn't. You have to use the construct function to define your properties. It's only then that the rest of the Functions in your Class will be able to "see" that data.
        2) What is "$this?" BTW: That "$this->snare=$snare;" thing... "$this->" is defined in the PHP Manual as...
The pseudo-variable $this is available when a method is called from within an object context. $this is a reference to the calling object (usually the object to which the method belongs, but possibly another object, if the method is called statically from the context of a secondary object).
If you're wondering where "$three, $blind, $mice" came from, fret not. What we're going to be doing in just a moment is passing three variables into our Method and those variables could be called anything. We could've called them "$moe, $curly and $larry." It's not the name as much as it's how we're identifying the digital "cell" that corresponds to the "column" of the of the digital spreadsheet that we've created that gives us a way to organize the data that's going to be arriving in just a moment.
It's just a geeky way of putting your finger on something and identifying it as part of the "thing" that you're looking at. So, with the example we're using, the '$this->' code is saying that 'As far as the class MyDrumset is concerned, the 'snare' variable is the cell / row that coincides with the '$snare' column we defined earlier.' It's just a way of mapping things out and giving everything a unique address / meaning within your code. Another way of looking at it is to envision a "tree." Whether it's "this" or any other idenfier, you're basically acknowledging a digital "tree" that's been created. That "tree" has any one of number of branches that can be grabbed on to programmatically. So when I say "$this->..." I'm taking hold of a "branch" that belongs to the "this" tree. I've also heard it referred to as the "arrow operator." Bottom line, it's what you're using to identify or specifiy a digital entity.   C) Constants You use "Construct" do define a variable that is generally unique / relevant to one or perhaps a couple of Functions within a particular Class. It can be "fluid," in that it can be defined according to data that's arriving via a form or something similar. In other words, it's foundational, but it's something that could conceivably be altered or changed depending on how you've crafted your code. A "Constant" on the other hand is usually hard coded into your script. It is immutable, for the most part. Very handy, but something you use only when you want to define something you don't see needing to change anytime soon. A good example might be the root directory of your app. For example... const ROOTURL='http://www.brucegust.com'; Something to keep in mind!
Before we get into some practical application, it's good to rehearse some good practices as far as things you want to include in your code every time. Always include: error_reporting(E_ALL); sometimes you may want to use "error_reporting(E_ALL ^ E_STRICT); " in the event you want to omit the errors generated by "E_STRICT" which hightlights code that is subject to be changed or deprecated. echo '<pre>'; "error_reporting(E_ALL)" tells your code to document errors wherever they may occur and the "<pre>" dynamic ensures that when any kind of text is printed, you get the appropriate line breaks included so the resulting errors. So, with echo '<pre>' you get : $this is defined (A) $this is not defined. $this is defined (B) $this is not defined ...otherwise, you get: $this is defined (A) $this is not defined. $this is defined (B) $this is not defined.
  D) Let's Do Something Now, check this out: We've defined a "class" as being something akin to a spreadsheet. That illustration actually works well because an Excel Spreadsheet is capable of doing more than just arranging data in the context of columns and rows. You can actually write formulas and do something with that data rather than merely displaying it - that's what you can do with a Class and a Function within an OOP enviornment. Quick FYI: A function written within a class is called a "Method." That's important because you can write functions outside of a Class. But when you write them as part of your "Class" (spreadsheet), you call it a "Method." Look at this: class MyDrumset { public $snare; public $kick; public $hihat; public function _construct($three, $blind, $mice) { $this->snare=$three; $this->kick=$blind; $this->hihat=$mice; } See, right here I'm going to add some functionality and print something. Yes, you see the word "function," but because it's written within a Class, it's actually called a "Method." public function printSomething() { print "Ideally, my "dream" drum kit consists of a {$this->snare} snare, a {$this->kick} bass drum and a pair of Sabian "{$this->hihat}" hihats."; } } Do you feel the energy? You smell something cooking on the stove, do ya? Alright... We've got some scaffolding and we've got a Method written within our class, so now let's create an "Object." Oooo...   E) Objects "Objects" are specific pieces of info that can now make sense because we're going to refer to them in the context of the Class that we previously defined. You see how all this is coming together? So, here's my "object:" $kit1 = new MyDrumset("Yamaha Piccolo", "28 inch", "Quickbeat"); $kit1->printSomething(); Again, you might be wondering "Where did you get '$kit1' from?" Again, it's not something you need to be concerned about, in terms of naming conventions. In order to use whatever functionality we've just created, we have to create a digital placeholder for it. The technical term is "instantiate." It's basically saying "I want the digital magic that I've just crafted to happen right...here!" So, in this example, I'm "instantiating" the MyDrumset class by programmatically saying "I want the 'MyDrumset' class to happen at this particular point in my page." In other words, I'm saying that I want to print, "Ideally, my "dream" drum kit consists of a {$this->snare} snare, a {$this->kick} bass drum and a pair of Sabian "{$this->hihat}" hihats." See how this is working? I've got three "cells" in my spreadsheet and I'm dictating what each of the values are in my "row" that I set up using my "constructor" function and now I'm passing three variables into what will be the "print" dynamic of my class. It's worth taking a second look at the way we instantiated "new MyDrumset" in that the order of the elements within the paranthesis has to coincide with the "$three, $blind, $mice" dynamic we set up a moment ago. Remember? The "construct" part of our Method was: public function _construct($three, $blind, $mice) { $this->snare=$three; $this->kick=$blind; $this->hihat=$mice; } So whatever occupies the position of "$three" is going to be processed as the "snare." Whatever is in the number two position of "$blind" is going to be intrpreted as the kick and so on. So, the result of my "$kit1" object is:
Ideally, my "dream" drum kit consists of a Yamaha Piccolo snare, a 28 inch bass drum
and a pair of Sabian "Quickbeat" hihats.
Before we proceed, let me pause long enough to elaborate a little on what we've just looked at... - "Classes" represent not just one "task," but potentially multiple tasks being performed every time you instantiate an instance of that Class. - "Functions" are individual tasks. The basic concept is the same in that you'll be passing variables into said "task," but where a Class has potentially several functions / tasks (and again, they're referred to as "Methods" when being executed within a Class), a Function is one solitary "thing" being done. - The Class begins with the definition of some Properties and in our example we did a "construct" where we established some placeholders - otherwise known as Objects - that corresponded to those Properties, much like a spreadsheet where the column headings were our Properties and the cells below each one of those column headings were our Objects.
Now, let's take a look at a real life piece of script and break it down. This is a script that's pulling from a database and then exporting that data into a CSV file. Very handy... There isn't any kind of "function" going on in this code, but that's what makes it a good starting point, just so you can see how things compare between a Procedural approach and an OOP approach. Ocassionally you'll see some notes in green that shows how the same code would've been written using a Procedural approach just so you can see how things would've been written.   A) Arrays Returned Within a Function Let's start with this: You're probably accustomed to selecting something from a database and then looping through the selected rows using a "while" dynamic. Perfectly fine... But, when you're using a function to select more than one particular piece of information, you're going to be storing the results of that query in a single "box." Again, going back to the spreadsheet illustration. When you're deploying a procedural approach, you query a database and you run through your results as a collection of rows. In that way, you've got a separate "box" for every row's worth of information. When you're using an OOP, you're select statement is typically stored within a function where you're returning a single "box" comprised of multiple rows - each row being tagged with a default value. Check it out: view "arrays within a function code...   B) CSV File Creation Here's an example of converting the results of a select statement and turning it into a downloadable CSV file. Take a look... view "CSV File Creation..."   C) Parsing of a JSON File In this example, you've got a lot of moving parts, but it's really cool to see how this functality works. You have a directory of compressed JSON files. Mind you, it's a directory. It's not a table in a database, it's a collection of files sitting in a file somewhere and we're going to be using code that can "see" those files. From there, we're going to be grabbing those files one at a time and "parsing" them. To parse a file basically means that you're breaking a pile of data into meaningful pieces - very handy. Click on the link above to see an example. This example uses a function, so you can start to see the utility of an OOP approach in that you do the heavy lifting once and then just benefit from its labor using minimal code for the rest of the app / page. Again, you'll see some notes in green that shows how the OOP script compares to its Procedural counterpart. Here we go... show "Parsing of a JSON File..." The previous examples / content do a pretty good job of getting you up to speed, not just in terms of theory, but also practical application. This next section takes things to a whole new level - yet another "tier" in terms of grouping. Up to this point, you've got: Now, we're going to look at taking OOP to another level using an "MVC" approach... Model, View, Controller is a term used to describe a particular type of approach to software design. You're basically organizing things into three different classifications. You've got... What follows are not just notes, but every shred of code that I put together in order to construct one of the more complicated apps I've built to date. Not so much in terms of "what" was done, but also because of the "way" it was done using this MVC / OOP approach.
By the way, I know this tutorial started out by my expressing my resolve to build an app that would normally be relatively easy using a familiar, procedural approach. This tutorial / journal has been crafted over several months, so suffice to say that the "app" being referred to at the beginning is a ship that has sailed. We're now moving on to far more complicated and elegant territory...! Also, I would be remiss if I didn't give credit where credit is due. The following is an approach authored by John Stokes. While he didn't ask for credit, I did want to reference him as the braintrust behind what you're about to see. If you would like to contact him, holler at me and I'll get you in touch. The following code / app can be seen by clicking here and there's an admin / commentary option that can be viewed by clicking here.
  A) Where We're Going - an Intro Let's start with this: Anytime you call a particular function or class, you kick things off by creating an "object." Now, pause for a moment because this rates a bit of a review.
The basic hierachy of OOP is Class >> Object >> Instance. Like this: $bring_it=new Class(); //instantiate the class $bring_it_object=$bring_it->bring_it_function(); //the "$bring_it_object" is the object of my $bring_it class. I'm calling a specific function within that class $bring_it_instance=$bring_it_object(returned result of object) //the specific result of the function represented by the $bring_it_object With this "MVC" approach to PHP / OOP, we visualize the page itself as the "object" of a particular class. In other words, the presence of a page instantiates a Class or, in this case, several classes.
So, let's say I've got your basic "index.php" page. How's that going to look? Like this:
/* CONTROLLER - csv_upload.php */ require_once('userpageclass.php'); require_once('csvClass.php'); require_once('user_uploadView.php'); $new_page= new AdminPage; $new_page->setBody($body); echo $new_page->display(); Tell me that doesn't look good! Basically, you've got 5-6 lines of code that simply "call" different classes and functions categorized under either the "View" or "Model" headings and you're orchestrating all of that in the context of your actual page, which is your "Controller." And what's great about all this is by keeping your functionality and your aesthetics separate, you've added yet another layer of organization that makes edits and even entire GUI overhauls very easy to faciliate! Let's take a look at what constitutes the "Controller" classes of this infrastructure...   B) The Controller This is a repeat of what we just discussed, but since it's a little more involved, it's worth repeating, especially given some of the additional functionality that's present.
  1. <?php
  2. require_once('adminpageclass.php');
  3. require_once('csv_AdminClass.php');
  4. require_once('csv_AdminView.php');
  5. $new_page= new AdminPage;
  6. $new_tool = new ToolAdmin;
  7. $tool_list=$new_tool->tool_list();
  8. $body = '<br><br><div style="float:right;"><select name="select62" size="1" onchange="MM_jumpMenu(\'new\',this,1)">
  9. <option value="#" selected>Tools</option>';
  10. $tool_rows=tool_select($tool_list);
  11. $body .=$tool_rows;
  12. $body.='
  13. <option value="">_______________________________</option>
  14. </select></div>Every time you upload a CSV file into a
  15. reporting tool, there\'s always a chance that some of your naming conventions don\'t match the
  16. field names of the database you\'re getting ready to interact with. To avoid that, this tool
  17. gives you the opportunity to "connect the dots" between your field names and the field names of
  18. the appropriate database. <br><br>At the end of the process,
  19. you\'ll have the opportunity to store your preferences so you won\'t have to do this every time
  20. you want to use a particular tool. Start by selecting the tool you want to use from the
  21. pulldown to the right.<br><br>To download a sample CSV file to see this
  22. app in action, click <A
  23. HREF="http://cascsapws1v.nss.vzwnet.com/sandbox/atlanta.csv" target="_blank">here</a>. Also, the list of tools that you see
  24. displayed in the pulldown menu to the right can be edited using the admin suite which can be accessed
  25. by clicking <a href="adm/admin.php"
  26. target="_blank">here</a>.<br><br>
  27. ';
  28. $new_page->setBody($body);
  29. Every time you upload a CSV file into a reporting tool, there\'s always a chance that some of your naming conventions don\'t
  30. echo $new_page->display();
  31. ?>
In this instance, I chose to put some of the text within the "Controller" dynamic. Generally, you put most of your "aesthetics" in your "View." Now, let's break it down: You've got "adminpageclass.php" on line two. This is an extension of the "htmlpage.class.php" page where you've got your basic HTML documented including your doctype, where you stylesheet is located that kind of stuff. Take a look:
  1. <?php
  2. session_start();
  3. //if the user has opted to use a preference they've documented previously, their session_id is going to be their email address
  4. if(empty($the_session_id))
  5.   {
  6.     if(isset($_POST['email_preference'])&& trim(!$_POST['email_preference']==""))
  7.       {
  8.           $the_session_id=trim($_POST['email_preference']);
  9.       }
  10.       elseif (isset($_GET['preference'])&& !$_GET['preference']=="")
  11.         {
  12.           $the_session_id=trim($_GET['preference']);
  13.         }
  14.       else
  15.         {
  16.           $the_session_id=session_id();
  17.       }
  18.   }
  19. //echo $the_session_id;
  20. require_once ('htmlclass.php');
  21. class AdminPage extends htmlpage
  22. {
  23.   const ROOTURL = 'http://www.brucegust.com/OOP/csv_upload';
  24.   //BASE URL for all pages
  25. public function __construct($title='CSV Upload Station')
  26.   {
  27.     parent::__construct($title);
  28.     $this->setMetaTags('<meta http-equiv="X-UA-Compatible" content="IE=9" />
  29.      <meta name="description" content="website description" />
  30.      <meta name="keywords" content="website keywords, website keywords" />
  31.     <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  32.      ');
  33.      $this->headerBottom ='
  34.      <map name="right_tabs">
  35.      <area shape="rect" coords="372,7,459,29" href="http://www.brucegust.com/" target="_blank">
  36.      <area shape="rect" coords="475,7,553,29" href="http://www.brucegust.com/portfolio/sample_code/" target="_blank">
  37.      <area shape="rect" coords="567,7,642,29" href="http://www.brucegust.com/campaign/OOP/" target="_blank">
  38.      <area shape="rect" coords="658,7,732,29" href="http://www.brucegust.com/campaign/portfolio.php" target="_blank">
  39.      </map>
  40.        <div id="header">
  41.          <div id="logo"></div>
  42.          <div id="right_tabs"><img src="http://brucegust.com/campaign/OOP/csv_upload/images/right_tabs.jpg" usemap="#right_tabs" border="0"></div>
  43.        </div>
  44.      <script>
  45.      $(document).ready(function() {
  46.      <link href="js/jquery-ui-1.10.4.custom/css/blitzer/jquery-ui-1.10.4.custom.css" rel="stylesheet">
  47.      });
  48.      </script>
  49.        <style>
  50.        td.grey {
  51.        background-color:#cccccc;
  52.        text-align:center;
  53.        font-weight:bold;
  54.        }
  55.       </style>
  56.      </div>
  57.        <div id="site_content"><br><br><h3 align="left" style="float:left;">CSV Upload Station Page</h3><div style="float:right;">'.$this->getNavBar().'</div><br><br>
  58.      ';
  59.      $this->footer = '
  60.        </div> <!-- close site_content -->
  61.        <footer>
  62.        </footer>
  63.      </body>
  64.      </html>';
  65.      $this->scripts='
  66.      <script language="JavaScript"><!--
  67.      function MM_jumpMenu(targ,selObj,restore){ //v3.0
  68.      window.open(selObj.options[selObj.selectedIndex].value, "_self");
  69.      if (restore) selObj.selectedIndex=0;
  70.      }
  71.      </script>
  72.      ';
  73.    }
  74.    protected function getSubnav()
  75.    {
  76.      $subnav='';
  77.     return $subnav;
  78.    }
  79.    public function webAddress()
  80.      {
  81.        $this->web_address=substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
  82.        return $this->web_address;
  83.   }
  84.    protected function getNavBar ()
  85.   {
  86.   $nav_bar ='
  87.     <a href="index.php">Home</a> | <a href="login.php">Login</a>
  88.     ';
  89.   return $nav_bar;
  90.    }
  91.   public function logout()
  92.   {
  93.     session_start();
  94.     session_destroy();
  95.   }
  96. }
  97. ?>
The biggest distinctive factor about "adminpageclass" is the addition of the security measure you see at line 5. Beyond that, it's pretty intuitive. The "csv_AdminClass.php" page is where you see all of your functionality in terms of selecting, inserting and editing data. This is your "Model" and you can see that broken down with some comments by clicking on the link below.   C) The Model Again, the "Model" is where you're storing all of your database functionality. This is a great way to keep your aesthetics separate from your functionality. view csv_AdminClass.php page 
  D) The View It's here where the "display" of the queries that are documented under the "Model" category is accomplished. Take a look: //a little function that first checks to see if any data is being submitted, the invokes the "check_tool" function to see if a record of the same name already exists. If not, the user is routed to the "tool_insert" function function tool_add() { if(isset($_POST['table_name'])&&!trim($_POST['table_name'])=="" AND (isset ($_POST['tool_name'])&&!trim($_POST['tool_name'])=="" )) { $new_admin= new ToolAdmin; $the_count=$new_admin->check_tool(); if($the_count>0) { header("location:tool_duplicate.php"); exit(); } else { $new_admin->tool_insert(); } } } //probably the most common way of displaying an array that was constructed in the csv_AdminClass.php (Model) page. In this instance, we're grabbing the array that was returned by the method "tool_list" and then displayed using the syntax you see below function tool_array($tool_list) { $briefcase=''; foreach ($tool_list as $tool) { $briefcase .=" {$tool['tool_name']} {$tool['table_name']} edit    delete "; } return $briefcase; } Again, this is just some brief commentary in order to better trace the logic of what's going on when you deploy an MVC approach to OOP. For more commentary and a working model of the app, click here.