Building Select Objects The select object is derived from an associative array. It expects a name for the entire structure and an associative array. For each element in the associative array, the index is translated to the value property of an option object. Also, the value of the array element becomes the text visible to the user. function gSelect($name, $listVals){ //given an associative array, //prints an HTML select object //Each element has the appropriate //value and displays the associated name $temp = “”; $temp .= “<select name = \”$name\” >\n”; foreach ($listVals as $val => $desc){ $temp .= “ <option value = \”$val\”>$desc</option> \n”; } // end foreach $temp .= “</select> \n”; return $temp; } // end gSelect function select($name, $listVals){ $this->addText($this->gSelect($name, $listVals)); } // end buildSelect Responding to Form Input One more SuperHTML object method quickly produces a name/value pair for each element in the $_REQUEST array. In effect, this returns any form variables and their associated values. function formResults(){ //returns the names and values of all form elements //in an HTML table $this->startTable(); foreach ($_REQUEST as $name => $value){ $this->tRow(array($name,$value)); } // end foreach $this->endTable(); } // end formResults 268 P H P 5 /M y S Q L P r o g r a m m i n g f o r t h e A b s o l u t e B e g i n n e r } // end class def ?> Summary This chapter introduced to the basic concepts of object-oriented programming. You saw that objects incorporate properties and methods. You learned how objects implement inheritance, polymorphism, and encapsulation. You experi- mented with the SuperHTML class and learned how to expand it when creating your own useful and powerful object classes. 269 C h a p t e r 7 W r i t i n g P r o g r a m s w i t h O b j e c t s CHALLENGES 1. Rewrite one of your earlier programs using the SuperHTML object. 2. Add support for more HTML tags in the SuperHTML class. 3. Create an extension of SuperHTML that has a custom header reflecting the way you begin your Web pages. 4. Add support for checkboxes and radio buttons. 5. Improve the buildTable() method so it automatically makes the first row or column a parameter-based header. 6. Rewrite an earlier program with custom objects. This page intentionally left blank T he Web has been changing since its inception. Two particular advances are especially important for PHP programmers to understand. The first is the concept of a content management system ( CMS ). This is a type of application that simplifies the creation and manipulation of complex Web sites. XML is a data management technique often used in CMS applications as well as other kinds of programming. PHP is an ideal language for implementing XML and CMS solutions. In this chapter you explore these exciting topics. You also do these things: • Explore some common CMSs in popular use • Build a basic CMS system using only one PHP program • Examine XML as a data storage scheme • Implement the simpleXML Application Programming Interface (API) for working with XML • Create a more sophisticated CMS using XML X M L a n d C o n t e n t M a n a g e m e n t S y s t e m s 8 CHAPTER Introducing XCMS You examine three different forms of CMS here. First, you look at a powerful CMS system called PHPNuke. Then you build a basic CMS using ordinary PHP. Finally you learn how to incorporate the power of XML to build the foundation of a pow- erful and flexible CMS engine. You begin by installing and modifying an existing system to create a custom, high-end Web site like the one featured in Figure 8.1. Because PHP-Nuke requires a functioning MySQL server, I did not include this particular example on the CD. PHP-Nuke is on this book’s CD, however, so use it to build sites just like this one. A CMS site can be extremely powerful, but you may not want all of the features of a high-end package like PHP-Nuke. On the other hand, you may wish to “roll your own” CMS. This type of program is very easy to build once you understand the basic concepts. By the end of the chapter you can build a site much like the one displayed in Figure 8.2. TRAP 272 P H P 5 /M y S Q L P r o g r a m m i n g f o r t h e A b s o l u t e B e g i n n e r FIGURE 8.1 You can develop this fancy page with a minimum of PHP programming. . different forms of CMS here. First, you look at a powerful CMS system called PHPNuke. Then you build a basic CMS using ordinary PHP. Finally you learn how to incorporate the power of XML to build the. site like the one featured in Figure 8.1. Because PHP- Nuke requires a functioning MySQL server, I did not include this particular example on the CD. PHP- Nuke is on this book’s CD, however, so use. these things: • Explore some common CMSs in popular use • Build a basic CMS system using only one PHP program • Examine XML as a data storage scheme • Implement the simpleXML Application Programming