User Tools

Site Tools


introduction

Get Familiar With LiteCart's Components

Coding with LiteCart is fun. And it's even more fun when you can do great things with the smallest amount of code.

This page will introduce you to some of the components in the LiteCart framework. Hopefully getting you a better understanding what they do and how they can be used.

LiteCart is a JIT designed MVC framework that is designed to have as little code and files as possible we possibly can. LiteCart is not built on a third party components. This may imply a little bit of a learning curve, but we think it will be worth the effort.

Feel free to step by the LiteCart Forums if you have questions.

Folder Structure

/
├── admin/
│   ├── *.app/
│   └── *.widget/
├── cache/
├── data/
├── ext/
│   ├── jquery/
│   └── ...
├── images/
├── includes/
│   ├── abstracts/
│   ├── boxes/
│   ├── entities/
│   ├── functions/
│   ├── library/
│   ├── modules/
│   ├── references/
│   ├── routes/
│   ├── templates/
│   └── wrappers/
├── install/
├── logs/
├── pages/
└── vqmod/
    ├── vqcache/
    └── xml/
Application Root
Backend
Admin apps
Dashboard widgets
Cache Directory
Data Storage
External/Extras/Vendor


Graphics

Class templates
Partials
Entity Objects
Helper functions
Libraries and system nodes
Modules
Read-only factory model reference objects to access entities
Route mapping
Views for HTML and Output
Service Layers and Clients
Installation wizard
Application logs
Controllers for web pages


vQmod Modifications

Please note the folder structure is subject to change in a future version.

Paths

When defining files and locations you will come a cross two directory definitions:

FS_DIR_APP The file system path to the application root directory e.g. /home/john/public_html/litecart/. Used to reference a file on the server side.

WS_DIR_APP The web system path to the application root directory e.g. /litecart/. Used to reference a resource in the web interface on the client side.

file_get_contents(FS_DIR_APP . 'subfolder/myfile.ext');
<img src="<?php echo document::link(WS_DIR_IMAGES . 'logotypepng'); ?>" />

Library Modules

The core of LiteCart contains of a set of system nodes stored in includes/library/. They are loaded automatically once requested and lack a prefix for their defined class names. This is the hear of LiteCart as these are the very central components of.

The main purpose of these nodes is to hold and process niched data. E.g. lib_language holds and processes anything language related.

To get the session currency maintained by ~/includes/library/lib_currency.inc.php:

currency::$selected['code']

To change the session currency:

currency::set('EUR')

Database

The lib_database library module handles all database activity. A connection to the default database is opened only when first needed.

To perform a MySQL query and fetch the results:

$query = database::query(
  "select * ..."
);

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

Functions

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.

To load ~/includes/functions/func_form.inc.php (if not previously loaded) and output a textarea:

<?php echo functions::form_draw_textarea('foo'); ?>

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

Entity Objects

Entity objects are class objects that control entity data and the mappings to their storage e.g. the database. By instantiating an entity object LiteCart will autoload the file constructing the object i.e. includes/entities/ent_product.inc.php and perform all the database queries needed for you.

To create a new product and give it an english name:

$product = new ent_product();
$product->data['name']['en'] = 'Test product';
$product->save();

To load customer ID 34 and update the email address:

$customer = new ent_customer(34);
$customer->data['email'] = 'user@domain.com';
$customer->save();

Please note prior to LiteCart 2.2.0 entity objects used the prefix ctrl_ instead of ent_.

To redirect to a product page (found in pages/product.inc.php) use document::ilink():

header('Location: ' . document::ilink('product', array('product_id' => 1234)));
exit;

To redirect to an external file e.g. images use document::link():

header('Location: ' . document::link(WS_DIR_APP . 'images/myimage.png'));
exit;

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_APP . 'images/myimage.png')); ?>">See Image</a>

Translations

For best convenience we are not using external files for storing translations. Instead we store them straight in the database. Anything that isn't already translatable inside the entity object (e.g. product description) is handled by the language library module.

While fetching a translation you can inject a default translation if not previously stored. This is done by providing the first default translation straight in the code. The default translation also functions as fallback if none is returned from the database.

English is always the framework language and language used for default translations. If translations are missing for any other languages 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):

echo language::translate('title_hello_world', 'Hello World'); 

Reference Objects

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

The reference objects are of factory design. They do not possess a whole set of data, but fetches it for you once requested.

Access the database and output the english product name for a product:

$product = new ref_product(id);
echo $product->name;

Or

echo reference::product(id)->name;

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 view file:

{snippet:foo_bar}

Then, to change layout file for the output to ~/includes/templates/my_template.catalog/layouts/my_layout.inc.php:

document::$layout = 'my_layout';

Template Views

LiteCart tries to separate logic from the user interface code 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/myview.inc.php supports the following syntax:

<h1>{snippet:helloworld}<h1>
<h1><?php echo $helloworld; ?><h1>
introduction.txt · Last modified: 2020/09/01 00:59 by admin