Online Test Banks
Score higher
See Online Test Banks
eLearning
Learning anything is easy
Browse Online Courses
Mobile Apps
Learning on the go
Explore Mobile Apps
Dummies Store
Shop for books and more
Start Shopping

How to Create a PHP Template Class

The heart of the template system is a PHP class that's responsible for gathering together the various parts of a given page. The Page class includes a few methods and properties. You instantiate the Page class as part of building each page. Follow these steps for this exercise:

  1. Open your text editor and create a new empty file.

  2. Place the following PHP code in the file:

    <?php
     
    class Page
    {
     
        public $type = "default";
        public $title = "My Web Site";
        public $titleExtra = "";
     
    }   //end Page class
     
    ?>
  3. Save the file as classPage.php in your document root.

Look how the first part of this code breaks down. The class Page is created and these three properties are declared:

  • Type: This corresponds to the type of page being displayed. By adding a type property, you can change the behavior of the various methods based on whether the type is default or another type. (This example has only a default type.)

  • Title: This appears in the browser's menu bar.

  • Extra title: Use this for additional pages, so that the pages can have different titles.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Advertisement

Inside Dummies.com

Dummies.com Sweepstakes

Win $500. Easy.