Aspen:Module Types
From Aspen Documentation
First, let's talk a little about terminology.
- Module
- A package of php code, html, css, images, etc that contain related functionality. This container works as an independent layer within the framework and may easily be removed, added, extended, etc.
- Interface "Application"
- An application built on top of the framework, which essentially is a group of modules. We call this an Interface Application because it's what the user actually interacts with.
An example, would be an e-commerce application. The Interface Application is an "E-commerce" package. Modules inside of it might be "Shopping" or "Checkout". If another developer has made a "Shipping" module, you can easily integrate it with your application.
Which to Choose
Creating modules and connecting things to the framework is a very flexible process so that they mold themselves to fit your needs.
It may be a little difficult to understand the various choices and combinations at first because of this flexibility. The default distribution of the framework comes with an example of both.
To start with, we recommend that you identify which of the categories below you fall into and take a look at the recommended setup. We explain a little bit more below.
- You already have website pages that you do not want to rewrite, but you need to add dynamic functionality to, or around.
- Go with "Website" Mode
- You would like to build a website using the framework as a basis.
- Go with "Application" Mode
- You would like to build a website with an admin or application-like component or section.
- Go with a combination of the two choices, or make them both "Applications".
- You would like to build a web-based application.
- Go with "Application Mode"
Included Module ("Website" Mode)
This type of module simply acts as a gateway between your separate php pages and the framework. Using this method, your code may access the framework methods only when needed, but your website/files will not actually be running from within the framework itself.
This method is most commonly used in the following scenarios:
- Dynamic Website
- Dynamic Website with Application(s) (typically an administrative back-end).
- Existing Applications using framework as an external resource.
At the top of your existing php file, you would enter something like:
<?php require('system/loader.inc.php'); ?> <?php $APP = load_module('Index'); ?>
Your selected module will then be loaded. Using the $APP variable you will have access to your module code, as well as most everything available within the framework.
An example of the Index module itself would begin as follows.
class Index extends Bootstrap { /** * @abstract Constructor, initializes the module * @param array $config Configuration settings passed through loader * @access public */ public function __construct($config){ parent::__construct($config); } }
Essentially, your script will be loading the bootstrap and all framework system classes directly.
Note: Using this method, the framework-only features of url handling, template caching, and security are not available.
Application Interface Module ("Application" Mode)
The second type of module is the application module. This essentially means that you're designing an application to sit on top of, and be run from within the framework. Aspen comes with a default example interface application called "Admin", which is typically used to develop administration tools to control content delivered through the front-end.
This method is most commonly used in the following scenarios:
- Dynamic website built/run within the framework
- Dynamic website with Application(s) (typically an administrative back-end).
- Web-based Application(s).
Your module file will utilize the application interface process rather than the bootstrap file. An example of this looks like:
class Index { /** * @var object $APP Holds our original application * @access private */ private $APP; /** * @abstract Constructor, initializes the module * @access public */ public function __construct(){ $this->APP = get_instance(); } }
There are various ways to combine these implementations. The most common mode is a combination of these two, and that's where we recommend you start as a beginner.
Things may not make sense quite yet, but don't worry. Once you start playing around, you'll get the picture.