TrailLamp is a lightweight, easy-to-use Php MVC framework that can be used to build web applications and REST APIs.

Last update: Jun 10, 2022

TrailLamp

Introduction

TrailLamp is a lightweight, easy-to-use Php MVC framework that can be used to build web applications and REST APIs.

Installation

Clone this directory and rename and place in your project directory

.env Parameters

APP_KEY: A unique application identifier

APP_URL: Main server url of your application with no ending slash example http://TrailLamp.test or https://yoursite.com

APP_ENC_KEY: A string used for encryption and decryption purposes

APP_NAME: Your application/API name

APP_VERSION: Your application or API version

MYSQLI_HOST: Your SQL host example localhost

MYSQLI_USER: Your SQL username, default is root

MYSQLI_PASSWORD: Your SQL password

MYSQLI_DATABASE: The database name

Usage

First set environment variables in .env file. Then point to the appropriate url on your browser or on your cmd or terminal, run the following command

  php index.php

TrailLamp needs a virtual host to run. For local development, Laragon can be used to develop applications with TrailLamp

Routing

All routes are set in the routes.php file. A simple route can be written as follows.

  $router->get("/", "[email protected]");

Here the request method is specified (TrailLamp currently supports only GET and POST requests)

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 functions. Eg

  $router->get("/", function(){
       echo "ok";
  });

All request values(like form values whose action was set to a specified route) can be gotten via your controller $request std class as follows

  $name = $this->request->name 

All uploaded files can be accessed via controller using

  $file = $this->files

Remember to use the appropriate request method in your routes file

Parameterized routes

Routes with parameters are called with the parameter names in curly brackets example

  $router->get("/about/{name}", "[email protected]");

Thus visiting url/about/Etorojah will call the Main method in the Controller class.

Multiple parameters are supported. To get the values of the parameters in the controller method, simply use

  $this->params[string param-name]

eg

  $this->params["name"]

will return Etorojah and can be used to perform any necessary action.

Parameters cannot be passed to a function. Always use controllers

Models

Models relate with the database directly. Every model created inherits the parent class TrailModel.

Creating Models

To create a model, run the following command on the TrailLamp console

  create model Modelname

Model names should start with a capital letter and the filename must be the same as the class name

By default, four model methods are created(create, read, update and delete). These methods can be deleted if not needed and your own defined methods called.

Performing queries with a model

Call the query method from your model method eg getprod() with the query string as a parameter

  $q = $this->query("SELECT * FROM products" );

You can then manipulate your results as seen fit eg

 while($r= mysqli_fetch_array($q)){
    //your code
     return result;
 }

Remember to always validate and sanitize your inputs before making queries

In your controller class method, reference the model using the include() method

  include("path/Model.php");

create a new instance of the model

  $prod = new ProductModel();

And call the model method to get the results

  $prod->getprod();

Deleting a model

Simply run the following command on your TrailLamp console

  delete model ModelName

Controllers

Controller perform majority of the app functions.

To create a controller, run the following command on the TrailLamp console

  create controller ControllerName

Controller file name and class name must be the same. All controllers inherit the default TrailLamp controller class

Views can be called via the controller using $this->view(string file name);

  $this->view('welcome');

Do not include the file extension

Redirects can also be performed via controller using $this->redirect(relative_url)

 $this->redirect('/about');

Remember to reference this route in your routes.php file

Views

All files in the view folder are views.

To create a view simply run the following on the TrailLamp console

  create view ViewName

Models can be called within views for example when displaying data from database

First reference the model file

Create an instance of the class

And call the class method from the view

Just three lines suffice in views

get-products(); ">
     include("Model.php");
     $prod = new Model();
     $prod->get-products();

In your model method the query and result can be echoed

'.$r["name"].' '; } ">
  $q = $this->query("SELECT * FROM products" );
  while($r= mysqli_fetch_array($q)){
    echo '

'.$r["name"].'

'
; }

Console

The console helps your easily run TrailLamp commands

Console commands

Create model

  create model Modelname

Create controller

create controller ControllerName

Create view

create view ViewName

View error log

view error log

Clear error log

clear error log

Delete model

delete model ModelName

Delete view

delete view ViewName

Delete controller

delete controller ControllerName

Migrations

To perform migrations simply rename your migration file to migrations.sql and then place in the migrations directory

Then point to https://url-path/migrations/migrations.php on your browser example

https://traillamp.test/migrations/migrations.php

Requests

All Ajax and fetch requests are to be routed to requests.php file in the TrailLamp request folder In your request, simply call the controller name and method separated by an @ using

$req->attachController($callback, $method) 

where callback is the controller name and method separated by an @ and the method is the request type

Encryptions

To encrypt a text or url, first include the utility/Encryption.php file

Create a new instance of the class Encryption()

And call the appropriate method encrypt() or decrypt() with the string/hash as parameter

encrypt("Hi"); or $enc->decrypt("hdhwkugehh48u38y38r88div3"); ">
include("utility/Encryption.php");
$enc = new Encryption();
$enc->encrypt("Hi"); or 
$enc->decrypt("hdhwkugehh48u38y38r88div3");

Errors

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

Contributions

Any issues found, please create an issue.

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

GitHub

https://github.com/EtorojahOkon/TrailLamp
You might also like...

Quite possibly the smallest MVC framework you'll ever use.

Swiftlet Swiftlet is quite possibly the smallest MVC framework you'll ever use. And it's swift. Licensed under the MIT license. Buzzword compliance โœ”

Feb 22, 2022

Leaf is a PHP framework that helps you create clean, simple but powerful web apps and APIs quickly and easily.

Leaf is a PHP framework that helps you create clean, simple but powerful web apps and APIs quickly and easily.

Leaf is a PHP framework that helps you create clean, simple but powerful web apps and APIs quickly and easily. Leaf introduces a cleaner and much simpler structure to the PHP language while maintaining it's flexibility. With a simple structure and a shallow learning curve, it's an excellent way to rapidly build powerful and high performant web apps and APIs.

Aug 6, 2022

Silex Skeleton - a fully-functional Silex application that you can use as the skeleton for your new applications

Silex Skeleton - a fully-functional Silex application that you can use as the skeleton for your new applications

Aug 5, 2022

Framework X โ€“ the simple and fast micro framework for building reactive web applications that run anywhere.

Framework X Framework X โ€“ the simple and fast micro framework for building reactive web applications that run anywhere. Quickstart Documentation Tests

Aug 9, 2022

LODSPeaKr is a framework for creating Linked Data applications in a simple and easy way

LODSPeaKr is a framework for creating Linked Data applications in a simple and easy way. You can see several applications created using LODSPeaKr.

Jun 23, 2020

๐ŸƒTermwind allows you to build unique and beautiful PHP command-line applications, using the Tailwind CSS API

๐ŸƒTermwind allows you to build unique and beautiful PHP command-line applications, using the Tailwind CSS API

Termwind allows you to build unique and beautiful PHP command-line applications, using the Tailwind CSS API. In short, it's like Tailwind CSS, but for the PHP command-line applications.

Aug 7, 2022

Symprowire is a PHP MVC Framework based and built on Symfony, using the ProcessWire CMS as DBAL and Service Provider.

Symprowire - PHP MVC Framework for ProcessWire 3.x Symprowire is a PHP MVC Framework based and built on Symfony using ProcessWire 3.x as DBAL and Serv

Jan 16, 2022

Multi-process coroutine edition Swoole spider !! Learn about Swoole's network programming and the use of its related APIs

swoole_spider php bin/spider // Just do it !! Cache use Swoole\Table; use App\Table\Cache; $table = new Table(120); // capacity size $table-column

Apr 22, 2021

๐Ÿ’ก Mudrock is a MVC PHP framework, which was inspired by the Laravel and CodeIgniter frameworks.

๐Ÿ’ก Mudrock is a MVC PHP framework, which was inspired by the Laravel and CodeIgniter frameworks

Nov 17, 2021
Related tags
FlyCubePHP is an MVC Web Framework developed in PHP and repeating the ideology and principles of building WEB applications, embedded in Ruby on Rails.

FlyCubePHP FlyCubePHP is an MVC Web Framework developed in PHP and repeating the ideology and principles of building WEB applications, embedded in Rub

Dec 21, 2021
a framework for WebDevelop based on the mvc structure. The name of this project for Fun because everyone can use it. Completely simple and powerful structure for all your projects

A_A (-.-) โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ |-| โ–ˆโ–„โ”€โ–„โ–„โ”€โ–ˆโ–„โ”€โ–ˆโ–ˆโ”€โ–„โ–ˆโ”€โ–„โ–„โ–„โ–„โ–ˆโ”€โ–„โ–„โ–„โ–„โ–ˆโ–„โ”€โ–ˆโ”€โ–„โ–ˆโ”€โ–„โ–„โ–„โ”€โ–ˆโ–ˆโ–€โ–„โ”€โ–ˆโ–ˆโ”€โ–„

Jun 29, 2022
Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.

Slim Framework Slim is a PHP micro-framework that helps you quickly write simple yet powerful web applications and APIs. Installation It's recommended

Aug 10, 2022
A super fast, customizable and lightweight PHP MVC Starter Framework to extend for your own...

PHPMVC A super fast, customizable and lightweight PHP MVC Starter Framework to extend for your own... How to Start Clone this repo - git clone https:/

Aug 8, 2022
Woski is a fast and simple lightweight PHP Framework for building applications in the realm of the web.
Woski is a fast and simple lightweight PHP Framework for building applications in the realm of the web.

Woski is a simple fast PHP framework for the Realm The Project Installation Clone the repository $ composer create-project clintonnzedimma/woski myApp

Apr 13, 2022
A Small modular PHP framework Build for web applications

MagmaCore__ This project is in active development. So is evolving constantly. As soon project gets to stable point. Due notice will be given Composer

May 13, 2022
REST APIs using Slim framework. Implemented all CRUD operations on the MySql database
REST APIs using Slim framework. Implemented all CRUD operations on the MySql database

PHP REST API using slim framework and CRUD operations ?? Hi there, this is a simple REST API built using the Slim framework. And this is for the folks

Jun 1, 2022
PHP Kafka client is used in PHP-FPM and Swoole. PHP Kafka client supports 50 APIs, which might be one that supports the most message types ever.

longlang/phpkafka Introduction English | ็ฎ€ไฝ“ไธญๆ–‡ PHP Kafka client is used in PHP-FPM and Swoole. The communication protocol is based on the JSON file in

Aug 12, 2022
PhpBoot is an easy and powerful PHP framework for building RESTful/Microservices APIs.
PhpBoot is an easy and powerful PHP framework for building RESTful/Microservices APIs.

?? tiny & fast PHP framework for building Microservices/RESTful APIs, with useful features: IOC, Hook, ORM, RPC, Swagger, Annotation, Parameters binding, Validation, etc.

Aug 7, 2022