+1 571-297-6383 | info@sonjara.com

Chapter 5: Components

In Fakoli, a set of files that perform a related purpose within your application would be organized into a Component. For example, the code for the Fakoli CMS feature that manages templates is stored in the component "template", the code for the Menu feature is stored in the component "menu." In fact, even components themselves need code to manage them, thus there is the component which is appropriately named "component."

Your application can extend or override Fakoli's components. In your application directory structure, you can add your own components in a folder called "component". You can name your components anything you wish except for names already used in Fakoli, unless you wish to override the component completely.

For example, your website might have a component called "order" for managing customer orders. Within that component, you would create one or more of the following folders:

  • admin:  contains any pages you wish to add to the CMS to enable systems administrators to manage the component's data or features. For example, in the order folder, you might have files "product_list" and "product_form" for entering the products for sale. Code files that contain supporting classes or functions for these admin files can be placed in a folder called "include" within the admin folder.
  • css: contains any custom css a component needs to render its pages properly.
  • datamodel: contains the files that describe the data model for the order component. For example, you might have a datamodel file order.inc that defines the class called "Order", and a file called product.inc that defines the product class. Data models are described in Chapter 2 of the Framework documentation.
  • handlers: contains code files that respond to user actions. For example, the order component could have a transaction handler that saves the transaction data that PayPal returns after the user completes a purchase. Handlers are also used to display modal dialogs called through JavaScript commands.
  • images: contains images and icons used in the component
  • js: contains any JavaScript files with MooTools classes and functions needed in the component's pages.
  • modules: contains any custom modules used in the component. A module can be rendered as a CMS Page or as a sidebar, such as a minicalendar or list of recent articles.
  • pages: contains all the code files for the component that are accessed directly in the website, rather than through the CMS. For example, you might have pages "order_form.inc" and "order_list.inc" for user placing orders and "order_fulfillment.inc" and "order_fulfillment_form.inc" for staff members who fill the orders and enter the shipping details.

Directly under the order folder, you could have files that include supporting classes such as order_view.inc and validate_order.inc.

Components that contain a data model must also contain a schema SQL file (e.g., order_schema.sql) with its table and view create statements and a code file containing the upgrade manager class to handle schema updates (e.g., order_upgrade_manager.inc)

Each component you write must contain a file called manifest.inc directly under the component's folder. This is the file that registers your component with Fakoli CMS, gives it a unique name within the CMS, and specifies whether it is enabled or not. The manifest also lets you specify where you want any admin files to appear within the CMS menu.

The following code is an example of a manifest for the order component:

class OrderManifest
{
	static function getComponentDefinition()
	{
		$component = new Component();
		$component->name = "order";
		$component->description = "Details of orders.";
		$component->author = "Jane Smith";
		$component->version = "1.0";
		$component->priority = 0;
		$component->enabled = true;
		
		return $component;
	}
	
	static function getAdminMenu()
	{
		return array
		(
			"Classification" => array
			(
                           "Products"	=> 
                             array("page" => "/admin/product_list"
                                    "role"	=> "admin"
                                    "weight" => 10)
			)
		);
	}	
	
	static function getStyles()
	{
		return array("/components/order/css/order.css");
	}
	
	static function getScripts()
	{
		return array("/components/order/js/order_manager.js");
	}

	static function subscribeToEvents()
	{
		return array("upgradeComponent"	     =>	array(OrderManager, upgradeComponent),
			 "ComponentScanComplete"     => array(OrderManager, setDefaults),
			"upgradeComponent"	     =>	array(OrderManager, upgradeComponent)
					);
	}
}

The manifest links the CMS admin page "product_list.inc" into the Classification menu with a weight of 10. The weight works like a sort order but allows you to be approximate, rather than exact in your assignments. A weight of 10 would place the menu item near the bottom if most other items are weighted less.

After you create a new component, you need to run a component scan to get Fakoli CMS to search for new components to be incorporated into the CMS. The Components menu item displays a list of all registered CMS components. At the bottom is a button "Scan for Component Updates." When clicked, Fakoli will find your new component through the manifest. When the scan is complete, your new admin menu item will appear under "Classification" and your order component will be included in the list of components.

Your component pages will also now appear in Sections under Component Pages items, available to be added to your site. Please note that before you can view any component page through the browser, you must add those specific pages to at least one section.


Chapter 6: Actions » « Chapter 4: CMS Pages