Download the PHP package etorojah/traillamp without Composer

On this page you can find all versions of the php package etorojah/traillamp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package traillamp

Traillamp

A lightweight, easy to use, MVC Framework for Php

What's New in V1.1.0

Documentation

Installation

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

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

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

Folder structure

Routing

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

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.

Or with a function using,

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

Thus visiting https://url/about/Etorojah 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

example

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:

example

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.

example

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.

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

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

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

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

They are listed below:

Rendering a View: view(view, parameters)

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

The 'parameters' parameter is optional. Example:

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

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

Redirects: redirect(route)

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

Encryption: encrypt(text)

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

Decryption: decrypt(hash)

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

Remember to set environment variable, ENCRYPTION_KEY

Sending Mails: sendMail(email, subject, message)

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

Remember to set all mail environment variables.

Load Models: loadModel(model)

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

Remember to always return model results in model methods.

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

example

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.

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

Same applies in Middleware methods.

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.

example

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

Model file name and classnames must be the same.

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

Views

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

example

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

In View:

Database query results can even be displayed In Controller:

In View:

Note the relative path ./app/public

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

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.

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

example

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

There are three types of schema Traillamp supports

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

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

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:

Other actions can be achieved by passing the correct parameters. To migrate a schema file, simply visit "https://domain.ext/path/migrations/"

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

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

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

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

The above can be solved as shown below

or

Any other issues found, please create an issue.

Contributing

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


All versions of traillamp with dependencies

PHP Build Version
Package Version
Requires twig/twig Version ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package etorojah/traillamp contains the following files

Loading the files please wait ....