Langsung saja ke contoh programnya, perhatikan kode program dibawah. Pada code program yang pertama adalah class dari menu. Pada class tersebuat kita membuat ada dua method atau function. Kode program pertama saya beri nama menu.php
<?php
class menuAtas{
var $data = array();
var $jlh = 0;
function displayMenu(){
echo "<table border='1' align='center' width='100%'><tr>";
for($j=0; $j<count($this->data); $j++){
echo "<td align='center'><a href='".$this->data[$j]['label']."'>".$this->data[$j]['name']."</a></td>";
}
echo "</tr></table>";
}
function addMenu($name, $label){
$this->data[$this->jlh]['name'] = $name;
$this->data[$this->jlh]['label'] = $label;
$this->jlh++;
}
}?>
class menuAtas{
var $data = array();
var $jlh = 0;
function displayMenu(){
echo "<table border='1' align='center' width='100%'><tr>";
for($j=0; $j<count($this->data); $j++){
echo "<td align='center'><a href='".$this->data[$j]['label']."'>".$this->data[$j]['name']."</a></td>";
}
echo "</tr></table>";
}
function addMenu($name, $label){
$this->data[$this->jlh]['name'] = $name;
$this->data[$this->jlh]['label'] = $label;
$this->jlh++;
}
}?>
Dan kode program yang kedua adalah untuk memanggil class yang ada pada menu.php diatas. Saya beri nama index.php
<?php
include "menu.php";
$form = new menuAtas();
$form->addMenu("Home","#.php");
$form->addMenu("Data","#.php");
$form->addMenu("Profile","#.php");
$form->addMenu("Contact","#.php");
$form->displayMenu();?>
include "menu.php";
$form = new menuAtas();
$form->addMenu("Home","#.php");
$form->addMenu("Data","#.php");
$form->addMenu("Profile","#.php");
$form->addMenu("Contact","#.php");
$form->displayMenu();?>
Demikian share tutorial dari saya, semoga bermafaat. GBU
0 comments:
Posting Komentar