Aspen:Creating A Module

From Aspen Documentation

Contents

Module Naming

Module files are named with their class name (i.e. "Blog"), an underscore, and their interface name. Both words are capitalized. If no interface name exists, then just the name of the module.

A module called "Blog" that has one admin section and one display class, would look like:

modules/Blog
/Blog_Admin.php - Holds code used in the "Admin" application.
/Blog.php Holds code used for the default public application.

Interface Naming

The Interface (or Application) name is essentially the name of the subfolder (from the root of the framework install directory) your code is running from.

An administration application for your website would be called "Admin" and would be in the /admin subfolder of your application. If you're website/application is not in any subfolder (from the root of the framework install) then the interface would be left empty.

Using modadmin

Aspen comes with a great timesaver called modadmin. Modadmin is a script you can use from the unix-based command line for automatically creating a basic module shell. Modadmin accepts the name for your module and your interface (if used).

The first thing you'll need to do is access this script via the command line. Just open the shell or Terminal for Mac OS X and use cd to change directories into your aspen installation folder.

modadmin requires two parameters and accepts a third.

Action
(Required)
Tells modadmin what you're planning on doing. Acceptable: "add" or "remove"
Module Name
(Required)
An alphanumeric name for your module (case insensitive).
Interface App Name
(Optional)
The name of your interface application if available.

For example, if I want to create a new module in the default aspen framework install base called "Test_Admin", I would run the following:

$ php modadmin.php add test admin

After it has completed, you should see:

A new module called "Test" has been created successfully.

Your code will appear in the modules/Test folder, and your new module has already been activated in the database. To access the new module, simply visit your framework install from a web browser and click the "Test" link.

If your module name matches a table in your database, all basic view, add, edit, and delete code and html will also be generated for you. This code allows you to begin using the new module in basic form, while also giving you the generated output to begin modifying (rather than usual rewrites necessary with scaffolding).

Removing

Removing a module can be done in the same manner as adding, with the add argument replaced with remove.

$ php modadmin.php remove test admin

Once the files have been deleted and the module has been de-activated from the database, you will see:

"Test" has been removed successfully.

Note: At this time modadmin does not force modules to perform any type of uninstall on module-specific tables when being removed.

Creating A Module Manually

We don't recommend this method as modadmin was made to eliminate this need. However, if you need to do so, please begin with creating the following basic files:

  • Create a folder for your module.
  • Create a php class file with the name of your module, an underscore, and the name of the interface application. If no interface, just the name of your module. The first letter must be capitalized and rest lower-case.
  • Create an xml registry file with at least the classname, name, and guid elements.
  • Create any templates.
  • Begin with a core of the class depending on module type.

Next: Blog Tutorial