Jump to content

Using PHP to create HTML widgets?


Liquid Fire

Recommended Posts

I have been told that i should using php to create "widgets" instead of using string html/css and was thinking maybe it a good idea.  I was think that i could create a class called CMenu and then when i wanted to add a menu to the site i would just do something like this:

$new_menu = new CMenu();
$new_menu->AddLink("www.phpfreaks.com", "PHP Freaks Website");
$new_menu->AddLink("www.phpfreaks.com", "PHP Freaks Website");
$new_menu->AddLink("www.phpfreaks.com", "PHP Freaks Website");
$new_menu->AddLink("www.phpfreaks.com", "PHP Freaks Website");

$new_menu2 = new CMenu();
$new_menu->AddText("PHP Freaks Website is cool");

 

now does nayone know of any tutorials or examples of doing this type of things?

Link to comment
https://forums.phpfreaks.com/topic/40359-using-php-to-create-html-widgets/
Share on other sites

Just look up classes, here's an example of how you would implement your first menu class:

 

<?php

class Cmenu
{
        var $links = array();

        function Cmenu()
        {}

        function AddLink($url,$title)
        { $this->links[] = array($url,$title); }

        function display()
        {
                echo '<ul>';
                foreach( $this->links as $link )
                {
                        echo '<li> <a href="'.$link[0].'" title="'.$title[1].'">'.$link[1].'</a> </li>' . "\n";
                }
                echo '</ul>';
        }
}

 

$new_menu->display(); would show the menu.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.