0

Writing a New Class

I have been writing and testing a new PHP class today to make me easier to create my new site menu bar called menu class. It contains a nested unordered list and a for loop to create the sub-menus. I wrote a couple of variables that use explode function to convert the input values to arrays. Here is the code I have written so far:

<?php
class menu {
    function  __construct() {
            // Output the menu
        echo "<div id='nav'>n";
        echo "<ul>n";

        $this->item("Home", "/");

        $this->item("Blog", "blog");

        $this->item("Portfolio", "portfolio",
                "Resume=>resume,
                 About Me=>about");

        $this->item("Projects", "projects",
                "ICAP<br />Interagency Coalition on Adolescent Pregnancy=>icap");

        $this->item("School Assignments", "assignments",
                "CA 272<br />Pro Website Dev=>ca272,
                 CA 282<br />PHP & MySQL=>ca282,
                 CA 288<br />Adv ColdFusion=>ca288,
                 CS 110<br />Computer Concepts=>cs110");

        echo "</ul>n";
        echo "</div>n";
    }

    function item($menuItem, $linkLocation, $subItems="") {
        echo "<li>n";
        echo "<a href='{$linkLocation}' title='{$menuItem}'>$menuItem</a>n";
            // Insert the sub-menu items if there is one
        if (!empty($subItems)) {
            $this->submenu($subItems);
        }
        echo "</li>n";
    }

    function submenu($itemaLink) {
        $itemaLinks = explode(",", $itemaLink);
        echo "<div class='submenu'>n";
        echo "<ul>n";
        for ($i=0; $i", $itemaLinks[$i]);
                    // This is used for my courses names
                $title = explode("<br />", $itemLink[0]);
                if(sizeof($title) == 1) {
                    $title[1] = $itemLink[1];
                }
                echo "<li>n";
                echo "<a href='{$itemLink[1]}' title='{$title[1]}'>{$itemLink[0]}</a>n";
                echo "</li>n";
            }
        }
        echo "</ul>n";
        echo "</div>n";
    }
}
?>

Note the $itemLink variable from the code above. This is based on the array format. Equal greater than (=>) symbol is variable and value connector in an array. This makes me easier to remember to add a link to the corresponding item. I also added $title array later in the process to differentiate between course title (e.x. CA 288) and course name (e.x. Advanced ColdFusion Development). You can see the example on my beta site. Note that I have not added any JavaScript to animate the menu. I will add MooTools-based animation later after I complete writing this menu class.

1

Create PDF without using PHP PDFlib

I never used PDFlib on my website because the extension isn’t available in the PEAR Modules of my web host. PDFlib is a PHP extension for generating PDF documents dynamically. PHP extensions need to be installed separately apart from PHP. In my one year experience with PHP, I only used GD extension to generate images for use with CAPCHA and other random images. Therefore I don’t have enough experience to talk about these extensions.

Recently when I was searching for some useful PHP tutorials, I stumble across a PHP class that can generate PDF documents without PDFlib extension. I thought this is very useful since my web host doesn’t provide the extension. It’s called FPDF. After some experiments by following its tutorials, I felt it’s not too difficult to use once you know the Object Oriented Programming way of PHP. The class also has dozens of extended classes. They can be copied and used as the extensions of FPDF. One thing that I don’t like about is its website. When I went to the site, the first thing I noticed was that it uses iframe. I don’t like iframe since it isn’t bookmarkable. I wonder why it doesn’t use PHP include instead of iframe since this is a PHP-based website. Fortunately, I can open the frame in a new tab by right-clicking appropriate frame in Firefox so I can add the Scripts page to Update Scanner to check new scripts update.