PHPackages                             etorojah/traillamp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. etorojah/traillamp

ActiveLibrary[Framework](/categories/framework)

etorojah/traillamp
==================

A lightweight MVC Framework for Php

1.1.0(3y ago)05[1 PRs](https://github.com/EtorojahOkon/Traillamp-package/pulls)PHP

Since Jun 10Pushed 1y ago1 watchersCompare

[ Source](https://github.com/EtorojahOkon/Traillamp-package)[ Packagist](https://packagist.org/packages/etorojah/traillamp)[ RSS](/packages/etorojah-traillamp/feed)WikiDiscussions latest Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

Traillamp
=========

[](#traillamp)

A lightweight, easy to use, MVC Framework for Php

What's New in V1.1.0
--------------------

[](#whats-new-in-v110)

- Better Url routing
- Support for additional request types
- Better error handling
- Robust Templating Engine
- Middlewares
- Additional Console Commands
- Support for all web servers
- Additional utilities
- Migration Schemas
- Flexible Models

Documentation
-------------

[](#documentation)

### Installation

[](#installation)

- #### Repository

    [](#repository)

Clone this directory using either git commands or download zip file

- #### Composer

    [](#composer)

Run the following command to install Traillamp via composer

```
    composer require etorojah/traillamp
```

Find the traillamp folder in the composer vendor folder Move to final destination and rename.

### Usage

[](#usage)

For local development, Any server environment application like Xampp, Lamp or Laragon can run Traillamp. First configure environment variables in app/env/.env file and then launch the application

### .env file Parameters

[](#env-file-parameters)

- **APP\_KEY**: A unique application identifier.
- **APP\_NAME**: Your application/API name.
- **APP\_VERSION**: Your application or API version.
- **DATABASE\_HOST**: Your database connection host, defaults to localhost.
- **DATABASE\_USER**: Your database connection username, default is root.
- **DATABASE\_PASSWORD**: Your database connection password.
- **DATABASE\_NAME**: The database name .
- **ENCRYPTION\_KEY**: A random string used as key for encryption/decryption.
- **MAIL\_HOST**: Mail host.
- **MAIL\_PORT**: Port to be used to send mails from the application.
- **MAIL\_USERNAME**: Mail username.
- **MAIL\_PASSWORD**: Mail username password.
- **MAIL\_SENTFROM**: Describes Mail sources e.g The Traillamp Support Desk.
- **SUBDOMAIN**: When true, development server is set up for subdomains or folder paths (, , )

If you are deploying the contents directly to the server root(htdocs,www,public\_html), set this value to false.

### Folder structure

[](#folder-structure)

- **console.exe**: Run Traillamp console commands with the console executable.
- **app**: Contains all resources to be worked with.
- **app/controllers/**: Application controllers are found here.
- **app/env/**: .env file is located here. Holds environment variables.
- **app/errors/**: Holds the error log file for error logging and reference purposes.
- **app/middlewares/**: Application middlewares are found here.
- **app/migrations/**: Holds Database migration schema files.
- **app/models/**: Application Models are found here.
- **app/public/**: Contains files referenced in views such as style sheetes, scripts and other files.
- **app/routes/**: Holds all route and routing files.
- **app/server/**: Default application codebase is stored here. Editing any file here may break your application.
- **app/utilities/**: Holds Mailing utility files.
- **app/views/**: View subfolders and files are found here

### Routing

[](#routing)

- #### Basic Routing

    [](#basic-routing)

All route files are found in **app/routes/** directory. A simple route without a middleware can be written as follows.

```
   $router::get("/", "WelcomeController@main");
```

The first parameter is the relative route path or url

The second parameter is the Controller name and the controller method separated by an @ sign.

Routes can also be called with function callbacks. Eg

```
     $router::get("/", function(){
        echo "ok";
    });
```

Routes can be called with Middleware specified for the route as the third parameter. A simple route with a middleware can be written as follows.

```
   $router::get("/", "WelcomeController@main", "WelcomeMiddlewarre@main");
```

Or with a function using,

```
    $router::get("/", "WelcomeController@main", function(){
        echo "ok";
        return true;
    });
```

Remember to use the appropriate request method in your routes file.

- #### Parameterized routes

    [](#parameterized-routes)

Routes with parameters are specified with the parameter names in curly brackets.

```
  $router::get("/about/{name}", "Controller@Main");
```

Thus visiting  will call the Main method in the Controller class with the name parameter assigned the value Etorojah.

Multiple parameters are supported. To get the values of the parameters simply use

```
    $this->parameter
```

example

```
    echo $this->name;
```

in the Middleware or Controller method.

A maximum of 4 parameters can be passed to a callback function.

You should use Controller/Middleware class methods for routes with more than 4 parameters.

You can pass parameters to Controller/Middleware callback functions as shown below:

```
    $router::get("/about/{name}", "WelcomeController@main", function($name){
        echo $name;
        return true;
    });
```

- #### Supported Requests

    [](#supported-requests)
- GET
- POST
- PUT
- PATCH
- HEAD
- DELETE
- #### Multiple route files

    [](#multiple-route-files)

To create a route file, simply run the command below in the Traillamp console

```
    create router-file

```

example

```
    create router-file admin_routes

```

### Controllers

[](#controllers)

Controllers form the backbone of your application. Controllers are found in the **app/controllers/** directory.

All Controllers inherit the default class **Controller**'s properties and methods in **Controller.php** file.

- #### Creating a Controller

    [](#creating-a-controller)

To create a Controller, run the following command on the Traillamp console

```
    create controller

```

example

```
    create controller Test

```

The above creates a Test.php Controller file in the **app/controllers/** directory.

Controller file name and classnames must be the same.

You can now add the created controller to any route of your choice.

- #### Default Properties and Methods

    [](#default-properties-and-methods)

The **request** property holds request parameters(array) for the given route and request type. This can be used to get form values and other request parameters.

Example, using a route with a POST request which handles a form:

```
    $name = $this->request["name"];
```

The **method** property holds the request type which may be useful in a code block. Example

```
    $name = $this->method;
    //returns POST for a POST request method etc
```

The **files** property holds the files sent as a request parameter to that route. Example

```
    $file = $this->files["photo"];

```

As shown earlier, route parameters can also be gotten using $this-&gt;parameter in controllers and middlewares.

- #### Inherited Methods

    [](#inherited-methods)

Inherited methods can be accessed from any Controller which extends the Parent Controller class.

They are listed below:

##### Rendering a View: **view(view, parameters)**

[](#rendering-a-view-viewview-parameters)

To render a view, use the inherited class method view which carries two parameters,

- view: string, name of the view(without file extension) .
- parameters: array, values to pass to view templating engine.

The 'parameters' parameter is optional. Example:

- **Without parameters:**

```
    $this->view("welcome");

    //subfolder view
    $this->view("includes.header");
```

The above renders a view **welcome.lamp** found in the **app/views** directory and **header.lamp** found in **app/views/includes/** subdirectory.

- **With parameters**

```
    $this->view("profile", ["name" => "John", "email" => "john@site.io"]);

```

The parameters are passed to the templating engine and can be used in the view file.

##### Redirects: **redirect(route)**

[](#redirects-redirectroute)

To redirect to another route, use the inherited class method redirect which carries one parameter,

- route: string, relative valid url route. Example

```
    $this->redirect("/about/me");

```

##### Encryption: **encrypt(text)**

[](#encryption-encrypttext)

To encrypt plain text, use the inherited class method encrypt which carries one parameter,

- text: string, lain text to encrypt. Example

```
    $hash = $this->encrypt("I am Batman");
    echo $hash;

```

##### Decryption: **decrypt(hash)**

[](#decryption-decrypthash)

To encrypt plain text, use the inherited class method decrypt which carries one parameter,

- text: string, lain text to encrypt Example

```
    $hash = $this->encrypt("I am Batman");
    $text = $this->decrypt($hash);
    echo $text;
    //returns I am Batman

```

Remember to set environment variable, ENCRYPTION\_KEY

##### Sending Mails: **sendMail(email, subject, message)**

[](#sending-mails-sendmailemail-subject-message)

To send mails, use the inherited class method sendMail which carries three parameters,

- email: string, valid email address.
- subject: string, subject of the message.
- message: string, message body. Example

```
    sendMail("john@site.io", "Greetings", "Hello to you");
```

Remember to set all mail environment variables.

##### Load Models: **loadModel(model)**

[](#load-models-loadmodelmodel)

To load and get database model results, use the inherited class method loadModel which carries one parameter,

- model, string, in the format Class@method Example

```
    $result = loadModel('Users@get_users');
```

Remember to always return model results in model methods.

### Middlewares

[](#middlewares)

Middlewares are found in the **app/middlewares/** directory.

All middlewares inherit the default Middleware class methods. Middlewares can be used for authentication and much more

- #### Creating Middlewares

    [](#creating-middlewares)

To create a Middleware, run the following command on the Traillamp console

```
    create middleware

```

example

```
    create middleware Test

```

The above creates a Test.php Middleware file in the **app/middlewares/** directory.

Middlewares file name and classnames must be the same.

You can now add the created middleware to any route of your choice.

- #### Default Properties and Methods

    [](#default-properties-and-methods-1)

Middlewares have same default properties as those in Controllers(See Controllers above).

- #### Inherited Methods

    [](#inherited-methods-1)

Inherited methods can be accessed from any Middleware which extends the Parent Middleware class.

Middlewares have same inherited methods as those in Controllers(See Controllers above).

All Middlewares should have a **return true** statement. This enables the application to transfer the logic to the controllers.

An exception will be thrown if this is not done.

Example: Using a middleware to check for account type

```
    $router::get("/accounts/{type}", "WelcomeController@main", function($type){
        if($type !== "user") {
            echo "You are not allowed to access this page";
            exit;
        }

        return true;
    });
```

Same applies in Middleware methods.

### Models

[](#models)

Models interact with the database. They are used to query databases. All Models inherit the default class **Model**'s properties and methods in **Model.php** file.

- #### Creating a Model

    [](#creating-a-model)

To create a Model, run the following command on the Traillamp console

```
    create model

```

example

```
    create model Test

```

The above creates a Test.php Model file in the **app/models/** directory.

Model file name and classnames must be the same.

- #### Default Properties and Methods

    [](#default-properties-and-methods-2)

Models inherit the database connection variable from the Parent Model.

Traillamp uses PDO for database connections and migrations. For flexibility purpose, however, you can use any other format to do this.

Simply connect to your database in the Model file or create a Database Connection class, include in in model file and use.

**Note:** Model methods must have a return statement. This makes it easy to pass the value to the Controller in the loadModel method.

Example Model method query using PDO

```
    public function main(){
        try {
            $sql = "SELECT * FROM table_name";
            $stmt = $this->db->prepare($sql);
            $stmt->execute();
            $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
            return $stmt->fetchAll();

        }
        catch (PDOException $error) {
            die("Error in query:\n".$error->getMessage());
        }

    }
```

### Views

[](#views)

Views are found in the **app/views/** directory. View files have the extension **.lamp**.

- #### Creating a View

    [](#creating-a-view)

To create a View, run the following command on the Traillamp console

```
    create view

```

example

```
    create view profile

```

The above creates a profile.lamp View file in the **app/views/** directory.

- #### Passing Parameters to View

    [](#passing-parameters-to-view)

Traillamp uses Twig as its templating Engine. Twig is easy to use. Check out Twig's documentation here. You can manipulate parameters passed to views from the controller in the view file using Twig's templating syntax. Example **In Controller:**

```
    $this->view('about', ['name' => 'David']);
```

**In View:**

```
    {{ name }}

```

Database query results can even be displayed **In Controller:**

```
    $result = $this->loadModel('Users@get_users');
    $this->view('about', ['users' => $result]);
```

**In View:**

```
    {% for user in users %}
        Name: {{ user.name }}
    {% else %}
        No Users found
   {% endfor %}

```

- #### Referencing external files

    [](#referencing-external-files)

Stylesheets and scripts in **app/public/** directory can be referenced in views Example

```

```

Note the relative path **./app/public**

### Utilities

[](#utilities)

The **mail.html** found in **app/utilities/** file's content can be replaced with your preferred Mail design.

However leave \*\*\*\*\*\*\*\*\*\* where you want the message body to go into.

### Console Commands

[](#console-commands)

Below is a list of Traillamp's Console Commands.

You can type --help in the Traillamp's console to see a full list Traillamp's of console commands.

- clear error log | Clears error log file
- view error log | Displays error log
- create controller | Creates a controller with filename and class
- create middleware | Creates a middleware with filename and class
- create model | Creates a model with filename and class
- create view | Creates a view with filename
- create router-file | Creates a router file with filename
- create schema-file | Creates a migration file
- remove controller | Deletes a controller with filename
- remove middleware | Deletes a middleware with filename
- remove model | Deletes a model with filename
- remove router-file | Deletes a route file with filename
- remove view | Deletes a view with filename

### Migrations

[](#migrations)

*Warning: This feature is still in development stage.*Migration schemas can be used to create and modify database and database tables. Migration schema files are found in **app/migrations**

- #### Creating Migration Schema Files

    [](#creating-migration-schema-files)

To create a schema file, run the following command on the Traillamp console

```
    create schema-file

```

example

```
    create schema-file users

```

The above creates a file users.php in **app/migrations**.

There are three types of schema Traillamp supports

- DatabaseSchema
- TableSchema
- ActionSchema

To create a schema, create an instance of the type of schema you want with appropriate parameters and call the migrate method of that class. Example

```
    //Database schema
    $schema = new DatabaseSchema($parameters);
    $schema->migrate();
```

- #### DatabaseSchema

    [](#databaseschema)

This class is used to create databases. It carries one parameter, the name of the database to be created. Example

```
    //new Database schema
    $dbname = "db_test";
    $schema = new DatabaseSchema($dbname);
    $schema->migrate();
```

- #### TableSchema

    [](#tableschema)

This class is used to create tables. It carries two parameters, the name of the table to be created and the table structure.

- name: string, table name
- structure: array, format \["col\_name" =&gt; \["type" =&gt; "", "length" =&gt; "", "null" =&gt; boolean\], ...\] Example:

```
    //new Table schema
    $tablename = "users";
    $schema = new TableSchema($tablename, [
        "email" => ["type" => "varchar", "length" => "255"],
        "fullname" => ["type" => "varchar", "length" => "255", "null" => true]
    ]);
    $schema->migrate();
```

**Note:** The id column should not be included in the structure.

- #### ActionSchema

    [](#actionschema)

This class is used to modify databases, tables and table columns. It carries one parameter, structure.

- structure: array, format \["action" =&gt; "", "target" =&gt; "", "target\_type" =&gt; "", "action\_type" =&gt; "", "data" =&gt; \["data\_type" =&gt; "", "column" =&gt; ""\]\]

*action:* can be either 'truncate' or 'alter'. *target\_type:* can be either 'database' or 'table'. *target:* can be either a database or table name. *action\_type:* can be either add, drop or modify. *data*-*data\_type:* any of the database table column data types (varchar, int, date, date-time) etc. *data*-*column:* table column name.

Example:

```
    //dropping a database
    $schema = new ActionSchema([
        "action" => "alter",
        "target" => "db_name",
        "target_type" => "database",
        "action_type" => "drop"
    ]);
    $schema->migrate();
```

```
    //dropping a table
    $tablename = "users";
    $schema = new ActionSchema([
        "action" => "alter",
        "target" => $tablename,
        "target_type" => "table",
        "action_type" => "drop"
    ]);
    $schema->migrate();
```

```
    //truncate a table
    $tablename = "users";
    $schema = new ActionSchema([
        "action" => "truncate",
        "target" => $tablename,
        "target_type" => "table"
    ]);
    $schema->migrate();
```

Other actions can be achieved by passing the correct parameters. To migrate a schema file, simply visit **""**

You can change this path in **routes.php** to any path of your choice by changing the path in the line below:

```
    $router::get("/migrations/", "MigrationController@main");
```

The **MigrationController** class handles migrations hence, the file **MigrationController** in **app/controllers/** should not be deleted unless it would not be used.

*Note* For security purposes, comment or remove the migration path from **routes.php** file when the application has been deployed.

### Error handling

[](#error-handling)

Any error while developing is shown on the screen. The error is also logged into the error\_log file for reference purposes.

The error log file can be cleared with the clear error log command

### Issues

[](#issues)

If you face parameterized routing conflicts, you can solve this by making one of the conflicting routes unique. Example

```
    $router::get("/about/{user}", "AboutController@main");
    $router::get("/profile/{id}", "ProfileController@main");
    //this may create a routing conflict
```

The above can be solved as shown below

```
    $router::get("/about/{user}", "AboutController@main");
    $router::get("/{id}/profile", "ProfileController@main");
    //routing conflict solved
```

or

```
    $router::get("/about/{user}/details", "AboutController@main");
    $router::get("/profile/{id}", "ProfileController@main");
    //routing conflict solved
```

Any other issues found, please create an issue.

### Contributing

[](#contributing)

To contribute to this project, send an email to **** or call **+234 803 264 5840**

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1429d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2745e185a593a33503080200853c6f447d1f66f5283627fb4b9539b844cd6fb2?d=identicon)[EtorojahOkon](/maintainers/EtorojahOkon)

---

Top Contributors

[![EtorojahOkon](https://avatars.githubusercontent.com/u/65219496?v=4)](https://github.com/EtorojahOkon "EtorojahOkon (2 commits)")

### Embed Badge

![Health badge](/badges/etorojah-traillamp/health.svg)

```
[![Health](https://phpackages.com/badges/etorojah-traillamp/health.svg)](https://phpackages.com/packages/etorojah-traillamp)
```

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.3k86.3M2.2k](/packages/symfony-symfony)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19462.3M1.3k](/packages/drupal-core)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6939.5M341](/packages/drupal-core-recommended)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
