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?
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.
- Base your system on pages and modules (widgets).
- Info of pages is saved in database table say "pages".
- A module (widgets) is a class containing meta-data (definition) and business logic.
- If you add a module to a page, its specific info is saved in database.
- Next time if you desire to have its instance, just pass the related parameters to its class and you have it.
- So that way you can use single definition of a module in different places and for different instances.
- You can add as many pages in database.
- User can add as many widgets in a single pages.
I'm not sure if this would help, but for me I wanted a framework that I could extend with functionality in terms of modules when required but with the minimal amount of database interaction in terms of storing information about the module. So I have a setup where I have modules in folders with files for settings, css, js and the actual class that have to follow very specific naming conventions. When adding a moddule, I need to add the folder and then update a list of modules in the frameworks base settings.
One of the settings designates which page(es) the module needs to be loaded for. If the module is required on every page then it's a (*). My framework base controller checks the modules list and then checks the page setting for the module to see if it should be loaded.
My framework displays the page by loading a template into the output buffer and storing at a public var which can then be accessed by any code throughout the framework. So then I can simply use str_replace to identify sections that need loading (for instance, there an interface tag in the template which designates the main content of the page) and then replace with the module content. So, a gallery module would replace the interface tag with the gallery on the gallery page whereas an article module would produce an article on the interface tag on the articles page.
Although I don't, I think most people use smarty tags for the replacements.
I think this works fine when you need a framework that you are using personally to deliver sites to clients. This probably wouldn't work as well if different people need to be able to use your framework.
精彩评论