freenity: this interests me too, I don't really have much experience of how others do it, but here's how I do it in my cms -
PHP Code:
// snipped to the main part
function field($params=array()){
if(method_exists($this,$params['type'])){
$op = call_user_func(array($this,$params['type']),$params);
return $op;
}
else{
return 'field type not defined';
}
}
now when I'm looping through my fields to build the form I call that method (field), I then have several core field types defined such as text,textarea,select,checkbox,radio, etc., example -
PHP Code:
// textfield - I've stripped out all the code so you can see basics
function textfield($params=array()){
return '<input type="text" name="" id="" value="" />';
}
So I could do something like -
PHP Code:
echo $object->field(array(
'type' => 'textfield',
));
Obviously these would be called internally, you wouldn't just echo the output, but I'm keeping my examples lean.
This method allows me to keep my core methods (textfield,textarea,etc.) in one place, but gives third parties the chance to 'extend' my class and call their own, i.e.
PHP Code:
function freenity($params=array()){
return 'Hello world';
}
echo $object->field(array(
'type' => 'freenity',
));
Alternatively, I could write an api call so people wouldn't need to extend my class, ie. $object->plugin(...);
Hope this spurs some ideas :)