OOPS through PHP
Following is a simple example of creating classes using PHP. I was trying to study OOPS through PHP. You can use this to create more complex class for creating form elements. Needs revision.
<?php
class FormControl{
var $control = array();
/*
Input parameters and create object. Name and type are obviously required
*/
function FormControl($controltype, $controlname,
$controlsize='',
$controlvalue='',
$controltitle='',
$controlmaxlength='',
$controlclass='',
$controldisabled='',
$controlid='',
$controlstyle='',
$controlaccesskey='',
$controltabindex='',
$controldir=''){
$this->control['type'] = $controltype;
$this->control['name'] = $controlname;
$this->control['size'] = $controlsize;
$this->control['value'] = $controlvalue;
$this->control['title'] = $controltitle;
$this->control['maxlength'] = $controlmaxlength;
$this->control['class'] = $controlclass;
$this->control['disabled'] = $controldisabled;
$this->control['id'] = $controlid;
$this->control['style'] = $controlstyle;
$this->control['accesskey'] = $controlaccesskey;
$this->control['tabindex'] = $controltabindex;
$this->control['dir'] = $controldir;
}
function returncontrol(){
$t = '<input ';
while(list($name, $value) = each($this->control)) {
$t .= ($value!=''? $name . '="'. $value.'" ':'');
}
$t .= ' />';
return($t);
}
function rendercontrol(){
echo $this->returncontrol();
}
}
$mycontrol = array();
$mycontrol[0] = new FormControl('text', 'txt_name','','some value');
$mycontrol[1] = new FormControl('checkbox', 'chk_name','','some value');
$mycontrol[2] = new FormControl('submit', 'Submit','','Submit');
for($i=0;$i<count($mycontrol);$i++)
$mycontrol[$i]->rendercontrol();
?>


2 Comments:
Hello dear
I just want to update you that
PHP 5 is fully Object Orientd Language so to refresh your knowledge i think you should have a look on PHP 5. By the way good efforts keep going.
thanks naresh,
I know PHP5 is totally OO. HAve u heard a rumour that Sun is going to take over PHP and promote it like Java. I said Humour.
Any way thanks for commenting.
Cheers
Post a Comment
<< Home