size = $size; $this->label = $label; } } class CharField extends Field { function __construct($size = 80, $label = '') { $this->editor = 'input type="text"'; parent::__construct($size, $label); } function get_db_type() { return 'VARCHAR('.$this->size.')'; } } class Model { function get_name() { return get_class($this); } function make_create_sql() { $str = ''; echo "\nCREATE TABLE `",strtolower($this->get_name()),"` (\n"; echo " `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,\n"; foreach ( get_class_vars($this->get_name()) as $x => $y) { echo ' `',$x,'` ',$this->$x->get_db_type(),",\n"; } echo ");\n\n"; } function make_form() { foreach ( get_class_vars($this->get_name()) as $x => $y) { echo $this->$x->label,': <',$this->$x->editor,' name="',$x,"\">\n"; } } function make_form_table() { echo " \n"; foreach ( get_class_vars($this->get_name()) as $x => $y) { echo ' \n"; } echo "
',$this->$x->label,'<', $this->$x->editor,' name="',$x,'" value="'.$this->$x->value. "\">
\n"; } } class Person extends Model { var $name, $address, $phone; function __construct() { $this->name = new CharField(40, 'Name'); $this->address = new CharField(40, 'Address'); $this->phone = new CharField(15, 'Phone'); } } $j = new Person(); $j->name->value = "Erkki Tapola"; $j->make_create_sql(); echo "
\n"; $j->make_form_table(); echo "
\n"; ?>