How to Build an About Page on a PHP Template
The Structure of a PHP Script
How to Add a Bunch of MySQL Data

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
How to Send an SQL Server to the MySQL Server
How to Add MySQL Accounts
PHP and MySQL Functions
How to Select a MySQL Database
How to Start Sessions in PHP with a Prepended File
Advertisement

Inside Dummies.com