In Liten, you can set regular cookies or secure cookies which are saved in a secure location on the server.

Cookie Settings

When instantiating a Liten application, you can set the cookie lifetime and/or you can set cookie lifetime via the set cookie or set secure cookie methods.

There are several settings you can set for regular and secure cookies:

Note that the default path setting for secure cookies is the /tmp/ directory. If your server gets rebooted for some reason on a regular basis, you might want to change this setting. Just make sure that it is set below the root directory and is inaccessible to the public.

Regular Cookie

In order to set a regular cookie, use the set method:

The $expires value is the number of seconds.

To retrieve a regular cookie, use the get method:

In order to unset a regular or secure cookie, use the remove method:

Secure Cookie

Secure cookies are similar to sessions in that the cookie value is a string which corresponds to a file saved on the server. Also, just like sessions, the cookie file could be deleted when the server is rebooted. However, unlike sessions, you won’t have old cookie files sitting on the server taking up space. If they have expired, they will be deleted.

A secured cookie file may look like the following:

The data in the cookie file is serialized and below is an example of the serialized data:


With object relational mapping, you don’t have to know structured query language (SQL) in order to write database queries. Liten and the ORM helps facilitate simple and rapid development and also allows both fluent sql queries as well as CRUD operations.



To create a new database connection, we need to instantiate the ORM class. Throughout the rest of the docs, we will use the variable $orm for the database connection.


Connect to a database table by calling the table() method.

An alternative to above is calling the database table as a method.


When calling the insert(array $data) method, $data can be passed as one dimensional array to insert one new record or multiple arrays to insert multiple records.

Single entry:

Multiple entries:


There are two ways to update a record, by using the active record pattern or by or by using the where clause.

Single entry:

The above can also be written as:

You can use the alternative save() instead of update().

Or you can use the set(array $data) or set($key, $value)

For multiple entries using set(array $data) and where($key, $value).


Save() is a shortcut to insert() or update().




Single entry:

Multiple entries:


Count all the entries based on where() clause.

Use count for a specific column name.


Max based on where() clause.


Min based on where() clause.


Sum based on where() clause.


Average based on where clause.



The fluent query feature of the ORM allows you to write simple queries without having to write SQL.


Returns a single record is found otherwise it will return false.

You can achieve the same above by using only the primary key and dropping the where clause.

Retrieving the entry


Find returns and ArrayIterator of rows found, otherwise it will return false.

Find also accepts a closure ( find(Closure $callback) ) to perform data manipulation.

Fluent Query Builder


Select all:

Select columns:


Where can be used to setup the where clauses and they work with find(), findOne(), update(), and delete(). This is the same for the where aliases as well.Repetitive call to where and it’s aliases will append to each other using the AND operator. Use _or() to mimic the OR operator.


There where aliases can help shorten the where examples above.

Primary key:

Not equal to:


Not like:

Greater than:

Greater than equal to:

Less than:

Less than equal to:

Where in:

Where not in:

Where null:

Where not null:

Where with OR and AND

Use _and_() / _or_() chained to any where clauses.



Order, Group, Limit, Offset




Status messages basically returns a cookie that was set when a particular action was successful or unsuccessful.


With Liten, you can use before route middleware, before router middleware, and after router middleware. Below are a few code examples of each.

Before Route Middleware

Before Router Middleware

After Router Middleware

Note: If the route handling function has exit()ed the run callback won’t be run. 

When rendering a view using Liten’s view object, there are two parameters that can be passed to the display() method.


You can create a layout (template) that other files (children) can extend. The show() method displays a section of content defined by the child view extending it.


Create a view that extends the layout and provides content for the show() section in the layout.


A somewhat alternative to default layouts is partial views which allows you to separate templates for headers and footers.


Liten sends true HTTP responses and returns a response back to the screen in json format.


Request Method

Every HTTP request has a method (i.e. GET or POST). You can obtain the current HTTP request method via the below request objects:


The routing feature of Liten, lets you map URI’s to HTTP request methods (GET, POST, PUT, DELETE, OPTIONS).

When a route matches, the attached route handling function will be executed. The route handling function must be a callable. Only the first route matched will be handled. When no matching route is found, an ‘HTTP/1.1 404 Not Found’ status code will be returned.

Shorthands for single request methods are provided:

There is also an alternative shorthand for request methods in the following format:

Here are some shorthand examples to above:

Another alternative to above is route matching. A particular code will run based on the HTTP Method sent.

Here is an example of using GET and POST.

Note: Routes must be hooked before $app->run(); is being called.

Route Patterns

Route patterns can be static or dynamic.

  • Static Route Patterns are basic URIs, e.g. /about.
  • Dynamic Route Patterns are Perl-compatible regular expressions (PCRE) that resemble URIs, e.g. /api/(\d+)

Commonly used subpatterns within Dynamic Route Patterns are:

  • \d+ = One or more digits (0-9)
  • \w+ = One or more word characters (a-z 0-9 _)
  • [a-z0-9_-]+ = One or more word characters (a-z 0-9 _) and the dash (-)
  • .* = Any character (including /), zero or more
  • [^/]+ = Any character but /, one or more

Downloading the PHP PCRE Cheatsheet may come in handy.

Subpatterns must be parenthesized in order to work. See example below:

When multiple subpatterns are defined, the route handling parameters are interpreted in the order which they are defined.

Subrouting / Grouping Routes

Use $app->group($baseroute, $fn) to group a collection of routes onto a subroute pattern. The subroute pattern is prefixed onto all following routes defined in the scope. e.g. Mounting a callback $fn onto /posts will prefix /posts onto all following routes.

Custom Error

The configuration for Liten is easy, simple and you can follow the example in the main index.php application file.

System Requirements

PHP 5.4+

Rewrite Rules


Nginx (root directory)

Nginx (subdirectory)


Hello World

To get started using the framework, you will need to instantiate a Liten application like below.

Once it is instantiated, you can create a new route: