Thread: Plugin System
View Single Post
Old 03-27-2008, 07:10 PM   #5 (permalink)
flyingbuddha
The Contributor
 
flyingbuddha's Avatar
 
Join Date: Jan 2008
Location: Birmingham, UK
Posts: 60
Thanks: 10
flyingbuddha is on a distinguished road
Default

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 :)
__________________
Pro. Geek
http://www.mikeholloway.co.uk
flyingbuddha is offline  
Reply With Quote
The Following User Says Thank You to flyingbuddha For This Useful Post:
freenity (03-28-2008)