Aspen:Creating An Application

From Aspen Documentation

By default Aspen comes with an application called "admin" that runs in the /admin folder. All modules call files with *_Admin.php will have access to and will run within this application.

For example, let's say that you want to create a second application that shares the same database as the "admin" application. You have two choices:

  1. Create a second named application.
  2. Create an unnamed application which runs from the root install directory.

Root Application

A root application replaces our basic, stand-alone index.php sample in the root directory. Instead of loading the framework as an external library it runs the framework modules just as the "admin" application would.

  • Copy the admin/index.php file to the root directory.
  • Open the new index.php file and change the LOADING_SECTION to:

define('LOADING_SECTION', '');
  • Change the modules/Index/Index.php script we provided (setup for the external script access) to work within the framework:

class Index {
 
	/**
	 * @var object $APP Holds our original application
	 * @access private
	 */
	private $APP;
 
 
	/**
	 * @abstract Constructor, initializes the module
	 * @return Index_Admin
	 * @access public
	 */
	public function __construct(){ $this->APP = get_instance(); }
 
	/**
	 * view
	 */
	public function view(){
		print 'here';
	}
}

You now have a new working application. To begin using templates inside the module, create modules/Index/templates. Be sure that any specific users / groups have proper permissions to your new application.


Named Application

The "admin" application is called a named application, because it has a name and does not reside in the root aspen directory. Anything related to it is also named *_admin". Module class file are called "*_Admin.php" and template folders would be called "templates_admin".

To create another named application, simply copy and rename the admin directory.

In this example, we'll call it "clients".

  • Open the new index.php file and change the LOADING_SECTION to:

define('LOADING_SECTION', 'Clients');

If visit the clients folder at this point, and you copied the "admin" demo, you will see the contents of the header and footer templates.

  • Copy the modules/Index/Index_Admin.php script we provided to work with this application instead. Name it the same as your new application: modules/Index/Index_Clients.php

class Index_Clients {
 
	/**
	 * @var object $APP Holds our original application
	 * @access private
	 */
	private $APP;
 
 
	/**
	 * @abstract Constructor, initializes the module
	 * @return Index_Admin
	 * @access public
	 */
	public function __construct(){ $this->APP = get_instance(); }
 
	/**
	 * view
	 */
	public function view(){
		print 'here';
	}
}

Now, you should just see "here" as the application is loading this class.