Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a module system within a framework

I'm looking for ways to implement a module system into my application framework, Modules would be class files that change the design in some way so that the would automatically integrate with user intervention.

My framework is a custom built framework but is very similar to codeigniter, just a little lighter.

The idea that I have is within the template files is to call on module positions, and have modules auto loaded and parsed

<html>
     <head>
         <title>Welcome to my site</title>
     </head>
     <body>

          <header> 
               ....
               <?php $this->call_modules('header') ?>;
          </header>

          <section>

               <aside>
                    <?php $this->call_modules('sidebar') ?>;
               </aside>

          </section>

     </body>
</html>

So that the following modules would get called and the contents would go in there place:

/system/applications/admin/modules/header/a.php
/system/applications/admin/modules/header/b.php
/system/applications/admin/modules/sidebar/a.php
/system/applications/admin/modules/sidebar/b.php

So that to me seems like it would work fine, but the problem is that I have never built a module system before, and I feel as these are more classed as hooks.

In my head i basically want a simple system that consists of 1 class file, and templates if required, the calss file would probably look like this:

class Module_HelloWorld extends Module
{
     public static function info()
     {
         return array(
             'name' => 'Hello Word',
             'version' => '1.0.0',
             'description' => 'Dispalys "hello World"',
             'author' => 'Robert Pitt',
         );
     }

     public function execute($context,$action)
     {
          //$context would be the current view at the point of execution for the view

          //$action would be header / sidebar
     }
}

So my question in a nutshell, What would be the best way to design a module system for my framework, allowing 3Rd party modules to be dropped within a directory and then installed from admin, without much user intervention?

like image 698
RobertPitt Avatar asked Oct 12 '22 01:10

RobertPitt


1 Answers

good luck with your mvc and cms. I have implemented same think some time ago, my approach was simple the first one came to my mind.

  1. Base your system on pages and modules (widgets).
  2. Info of pages is saved in database table say "pages".
  3. A module (widgets) is a class containing meta-data (definition) and business logic.
  4. If you add a module to a page, its specific info is saved in database.
  5. Next time if you desire to have its instance, just pass the related parameters to its class and you have it.
  6. So that way you can use single definition of a module in different places and for different instances.
  7. You can add as many pages in database.
  8. User can add as many widgets in a single pages.
like image 77
Imran Naqvi Avatar answered Oct 27 '22 10:10

Imran Naqvi