Building a "modular" PHP site

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi everyone

Not really a specific PHP problem this, but...

I have been pondering over building a "modular" site which accepts  
add-ons built by other people.   I was wondering if anyone has any links  
  to any reading material on how you build this kind of facility into  
your site?

Obviously I could take something like Mambo's source and try to fathom  
out how their com_ type modules work, but I once looked at  
Mambo/Joomla's source and the code was a lot to take in in one go.

Does anyone have any good short examples or links to articles that  
explain how you make a site that accepts 'add-ons'/'modules', ie. a  
quickly and easily extendable site?


Tyno Gendo.

Re: Building a "modular" PHP site

Tyno Gendo wrote:

Quoted text here. Click to load it

The basic technique is this:

1. Provide a plugin registration function, which we'll call, say,
"plugin_register". When a plugin is loaded, it will call your
plugin_register function and tell your site at least the following

    1. How to use the plugin -- i.e. provide a function name
       or a class name that the site can use to access the
       functionality of the plugin;

    2. When to use the plugin -- this is normally done via
       a named hook.

So a particular plugin might be defined like this:

        function tobys_plugin ()
            echo "<!-- Hello World -->\n";
        plugin_register('tobys_plugin', 'onpagefinished');

Your plugin_register function would then add "tobys_plugin" to a list of
functions that need to be run when the page has finished outputting.

Then in the rest of your code, add you hooks. For example, at the end of
each page, you'd have:


where run_plugins looks at the list of registered plugins and runs the ones
that have registered using that hook.

That's the simplified version. In real life, to allow the plugins to be
more useful, you'll often want to pass them particular parameters, such as
the current URL, the login name of the currently logged in user, etc. I'll
leave you to figure that out on your own.

Toby A Inkster BSc (Hons) ARCS
Contact Me ~
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!

Re: Building a "modular" PHP site

Toby A Inkster wrote:
Quoted text here. Click to load it

Excellent, thanks for that reply.  I will have a toy around with  
something and of course follow up my post with an example when I get  
around to it.

Site Timeline