Building a "modular" PHP site

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tyno Gendo

    Building a "modular" PHP site

    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?

    Thanks

    Tyno Gendo.
  • Toby A Inkster

    #2
    Re: Building a "modular&q uot; PHP site

    Tyno Gendo wrote:
    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?
    The basic technique is this:

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

    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:

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

    Your plugin_register function would then add "tobys_plug in" 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:

    <?php
    run_plugins('on pagefinished');
    ?>

    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 ~ http://tobyinkster.co.uk/contact
    Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

    * = I'm getting there!

    Comment

    • Tyno Gendo

      #3
      Re: Building a &quot;modular&q uot; PHP site

      Toby A Inkster wrote:
      Tyno Gendo wrote:
      >
      >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?
      >
      The basic technique is this:
      >
      1. Provide a plugin registration function, which we'll call, say,
      "plugin_registe r". When a plugin is loaded, it will call your
      plugin_register function and tell your site at least the following
      information:
      >
      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:
      >
      <?php
      function tobys_plugin ()
      {
      echo "<!-- Hello World -->\n";
      }
      plugin_register ('tobys_plugin' , 'onpagefinished ');
      ?>
      >
      Your plugin_register function would then add "tobys_plug in" 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:
      >
      <?php
      run_plugins('on pagefinished');
      ?>
      >
      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.
      >
      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.

      Comment

      Working...