MVC
Mon Feb 21 08:01 System-generated article

Introduction  

The Bug Genie uses an MVC framework, heavily inspired by the Symfony framework. The Bug Genie tries to follow the MVC separation strictly, and borrows several well known concepts from the Symfony framework. If you've worked with this framework before, files such as actions.class.php and the routing system should be familiar concepts.

Directory hierarchy  

 thebuggenie
   - core
     - B2DB
     - classes
       - B2DB
     - lib
     - templates
   - modules
     - main
       - classes
         actions.class.php
       - templates
         index.html.php
   - thebuggenie
     - css
     - js
     - themes
       - oxygen


Class autoloading  

The Bug Genie has a class autoloading mechanisms that will look for classes in specific folders and files. Following recommended php coding conventions, classes are expected to be found in the file Classname.class.php. The Bug Genie will look for classes in the following directories:
  • core/classes
  • modules/<modulename>/classes
In addition, any B2DB (table-) classes are expected to be found in a B2DB subdirectory under the classes folder. You're free to put them in the classes folder directly, but for consistency, B2DB classes are located in core/classes/B2DB and modules/<modulename>/classes/B2DB.

If you have any special classes, interfaces or Exception classes you want to include specifically before any other classes, The Bug Genie will look for a file called generics.class.php. If this file is found, it will be automatically be included before any autoloading takes place.

Adding class-paths to the autoloader  

As mentioned above, The Bug Genie will automatically look through the classes directory in your module directory. If you want to add any other directories to the autoloader, use the static method addClasspath() in TBGContext.

Example:
TBGContext::addClasspath('/my/valid/path/');
This will add the path to The Bug Genies class autoloader. Usually this is not necessary, but may be desired for some external libraries or classes.

Actions and components classes  

Every module that uses routes is expected to have an actions class, named ModulenameActions, which should extend the TBGAction class. This special class is saved in the file actions.class.php inside the classes directory, and is autoloaded if it exists.

If your module uses components, you will have to create a components class ModulenameActionComponents, extending the TBGActionComponent class (Notice the plural form in the child classes).

Examples: my_module/classes/actions.class.php:
/**
 * Example actions class for mymodule
 */
class mymoduleActions extends TBGAction
{

	/**
	 * Index action
	 *  
	 * @param TBGRequest $request
	 */
	public function runIndex(TBGRequest $request)
	{
	}

}


my_module/classes/actioncomponents.class.php:
/**
 * Example components class for mymodule
 */
class mymoduleActionComponents extends TBGActionComponent
{

	/**
	 * Menu component
	 */
	public function componentMenu()
	{
	}

}


Templates  

Core template files are located in the core/templates folder. The templates there are the ones decorating every page, the header, menu and the footer. If you ever want to change the global header, menu or footer, edit the template files located here. Keep in mind that these template files may be overwritten on updates, so back up your changes before you update to newer versions.

Module templates  

Module templates are found in the modulename/templates folder. This is also where component templates and partial templates are found. Main templates (associated with an action) are called (lowercase) <actionname>.<format>.php, whereas template partials and component templates are called (lowercase) _<componentname>.inc.php and _<templatename>.inc.php. Notice the difference, with both a leading underscore, and the .inc.php extension.

Example (template file for the runIndex() action above, standard html version):
 thebuggenie
 - modules
   - mymodule
     - templates
       index.html.php


Example (template file for the componentMenu() component above):
 thebuggenie
 - modules
   - mymodule
     - templates
       _menu.inc.php


For a more detailed explanation about templates, components and template partials, see their respective documentations.

Attachments 0

Comments 0

/unthemed/mono/no-comments.png
Expand, collaborate and share
Post a comment and get things done