Developer Tutorial

System Model

The system core of LiteCart contains of a set of library modules or system nodes that are loaded automatically upon a page load. The main purpose of a system node is to hold and process information upon certiain stated events.

To call the query() class method defined in ~/includes/library/


A connection to the default database is opened only when first needed.

To pass a MySQL query and fetch the results:
$query = database::query(
  "select * ..."

while ($row = database::fetch($query)) {


No need to keep track of included function files. Functions can be dynamically loaded through the system library module. This means the files defining the functions will be loaded once the functions are requested.

Note: All function names must be begin with the file basename and be stored in ~/includes/functions/.

To load ~/includes/functions/ (if not previously loaded) and call form_draw_textarea():


Controllers are class objects that control data. Any class files are automatically included upon request.

To create a new product and give it an english name:
$product = new ctrl_product();
$product->data['name']['en'] = 'Test product';
To update the e-mail address for customer id 34:
$customer = new ctrl_customer(34);
$customer->data['email'] = [email protected]';

Reference Objects

Reference objects are read-only class objects that can dynamically return partial parts of a data set.

Access the database and output the english product name for a product:
$product = new ref_product(id);
echo $product->name['en'];

As of LiteCart 1.3 the following does the same thing but caches all loaded data during the page load.

echo catalog::product(id)->name['en'];

Internal Links

To redirect to the search page (found in pages/ use document::ilink():
header('Location: ' . document::ilink('search'));

External Links

To redirect to an external file e.g. images use document::link():
header('Location: ' . document::link(WS_DIR_IMAGES . 'myimage.png'));
When special characters are not allowed, i.e. inside HTML element parameters use document::href_link():
<a href="<?php echo document::href_link(WS_DIR_HTTP_HOME . 'search.php')); ?>">My link</a>


For convenience we are using injection based translations stored in the database. English is always the framework language. If translations are missing for any other language an english translation will be returned.

To output a translation for title_hello_world and inject an english translation to the database (if not previously injected):
language::translate('title_hello_world', 'Hello World')

Template Layouts

The document library module holds global snippets of content that are output to placeholders in a layout or view file. Any placeholders that do not have snippet content will be removed before output to browser.

To store a global snippet named foo_bar:
document::$snippets['foo_bar'] = '<h1>Foo bar!</h1>';
To insert a placeholder for the snippet content in a page layout file:
<!--snippet:foo_bar--> or snippet:foo_bar
Then, to change layout file for the output to ~/includes/templates/my_template.catalog/layouts/
document::$layout = 'my_layout';

Template Views

LiteCart tries to separate logic from the design by the use of views.

Gather some data and pass to a view:
$my_content = new view();
$my_content->snippets['helloworld'] = 'Hello World';
echo $my_content->stitch('views/myview');
The template view file includes/yourtemplate/views/ supports the following syntax:
<h1><?php echo $helloworld; ?><h1>
This is another annoying site cookie notice. Just as almost every site on the internet uses cookies, so are we!