Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ingeniasoftware/luthier-ci

Improved routing, middleware support, authentication tools and more for CodeIgniter 3 framework
https://github.com/ingeniasoftware/luthier-ci

codeigniter codeigniter-framework luthier-ci php router

Last synced: 8 days ago
JSON representation

Improved routing, middleware support, authentication tools and more for CodeIgniter 3 framework

Awesome Lists containing this project

README

        



**Luthier CI** is an awesome set of core improvements for CodeIgniter 3 that makes the development of APIs (and websites in general) more easy!

## Features

* Easy installation via hooks
* Laravel-like routing: prefixes, namespaces, anonymous functions as routes, route groups, CLI routes, named parameters, optional parameters, etc.
* Middleware support
* Authentication library with SimpleAuth template
* PHP Debug Bar integration (experimental)

## Requirements

* PHP >= 5.6.0 (PHP 7 compatible)
* CodeIgniter >= 3.0

## Installation

#### Step 1: Get Luthier CI with Composer

```
composer require luthier/luthier
```

#### Step 2: Enable Hooks and Composer autoload

```php
load->view('some_view');
});
```

You can assign names to your routes so you don't have to worry about future url changes:

```php
Route::get('company/about_us', 'testcontroller@index')->name('about_us');
```

To retrieve a named route, use the `route()` function:

```php
My link!
// Link
```

If the route has parameters, pass a second argument to the function with an array of their values:

```php
= route('route_name', ['param1' => 'value2', 'param2' => 'value2' ... ]); ?>
```

#### Route Groups

Group routes is possible with the `Route::group()` method. All routes
inside the group will share the *prefix* (first argument) and, optionally, another property (*namespace*, *middleware*, etc.)

```php
// Prefix only
Route::group('prefix', function(){
Route::get('bar','test@bar');
Route::get('baz','test@baz');
});

// Prefix and shared properties
Route::group('prefix', ['namespace' => 'foo', 'middleware' => ['Admin','IPFilter']], function(){
Route::get('bar','test@bar');
Route::get('baz','test@baz');
});
```

## Middleware

All the middleware must be defined in the routes files (`application/routes/web.php`, `application/routes/api.php`, `application/routes/cli.php`)

```php
# Route middleware:
Route::put('foo/bar','controller@method', ['middleware' => ['Test']]);

# Route group middleware:
Route::group('site', ['middleware' => ['Admin']], function(){
// ...
});

# Global middleware:
Route::middleware('Admin', 'pre_controller');
```

The middleware files must be saved in the `application/middleware` folder. If not exists, you must create it first. A middleware file is any php class that implements the `Luthier\MiddlewareInterface` interface and with a public `run()` method, which is the entry point. It's strongly advised to name all your middleware with CamelCase and avoid name conflicts with your controllers.

This is an example of a middleware:

```php