All Projects → ingeniasoftware → Luthier Ci

ingeniasoftware / Luthier Ci

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

Projects that are alternatives of or similar to Luthier Ci

Tieguanyin
Activity Builder.
Stars: ✭ 113 (-12.4%)
Mutual labels:  router
Django Macros Url
Django Macros URL. Routing must be simple as possible
Stars: ✭ 121 (-6.2%)
Mutual labels:  router
Http Router
🎉 Release 2.0 is released! Very fast HTTP router for PHP 7.1+ (incl. PHP8 with attributes) based on PSR-7 and PSR-15 with support for annotations and OpenApi (Swagger)
Stars: ✭ 124 (-3.88%)
Mutual labels:  router
React Page Layout
Create layouts for react
Stars: ✭ 117 (-9.3%)
Mutual labels:  router
Universal Router
A simple middleware-style router for isomorphic JavaScript web apps
Stars: ✭ 1,598 (+1138.76%)
Mutual labels:  router
The router
TheRouter is a software packet router based on DPDK an NPF libraries.
Stars: ✭ 123 (-4.65%)
Mutual labels:  router
Netcopa
Network Configuration Parser
Stars: ✭ 112 (-13.18%)
Mutual labels:  router
Codeigniter Angularjs App
Sample App based on CodeIgniter and AngularJS
Stars: ✭ 127 (-1.55%)
Mutual labels:  codeigniter
Tinypart
TinyPart is an iOS modularization framework implemented by Ojective-C. It also supports URL-routing and inter-module communication. TinyPart是一个由Objective-C编写的面向协议的iOS模块化框架,同时它还支持URL路由和模块间通信机制。
Stars: ✭ 120 (-6.98%)
Mutual labels:  router
Weave
A simple CLI router for wiring together several sources behind a single HTTP endpoint
Stars: ✭ 125 (-3.1%)
Mutual labels:  router
Rabbits
A router module for Android application.
Stars: ✭ 118 (-8.53%)
Mutual labels:  router
Beamer
A router that lets you navigate through guarded page stacks and URLs using the Navigator 2.0 API effortlessly.
Stars: ✭ 114 (-11.63%)
Mutual labels:  router
Hoosk
Hoosk Codeigniter CMS
Stars: ✭ 123 (-4.65%)
Mutual labels:  codeigniter
Alien
A lightweight and fast http router from outer space
Stars: ✭ 115 (-10.85%)
Mutual labels:  router
Bsdrp
BSD Router Project
Stars: ✭ 126 (-2.33%)
Mutual labels:  router
Router
🍭灵活的组件化路由框架.
Stars: ✭ 1,502 (+1064.34%)
Mutual labels:  router
Ansible Openwisp2 Imagegenerator
Automatically build several openwisp2 firmware images for different organizations while keeping track of their differences
Stars: ✭ 122 (-5.43%)
Mutual labels:  router
Fastroute
Simple, idiomatic and fast 161 loc http router for golang
Stars: ✭ 128 (-0.78%)
Mutual labels:  router
React Redux Graphql Apollo Bootstrap Webpack Starter
react js + redux + graphQL + Apollo + react router + hot reload + devTools + bootstrap + webpack starter
Stars: ✭ 127 (-1.55%)
Mutual labels:  router
Router Lab
Lab for Network Principles 2019-2020 fall, 2020-2021 spring and 2020-2021 fall
Stars: ✭ 124 (-3.88%)
Mutual labels:  router

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
# application/config/config.php

$config['enable_hooks'] = TRUE;
$config['composer_autoload'] = TRUE;

Step 3: Connect Luthier CI with CodeIgniter

Set the hooks:

<?php
# application/config/hooks.php

defined('BASEPATH') OR exit('No direct script access allowed');

// (...)

$hook = Luthier\Hook::getHooks();

Set the Luthier CI routes:

<?php
# application/config/routes.php

defined('BASEPATH') OR exit('No direct script access allowed');

// (...)

$route = Luthier\Route::getRoutes();

Initialization

The first time that Luthier CI runs, several files and folders are created:

  • routes/web.php: Default HTTP-Based routes
  • routes/api.php: AJAX routes
  • routes/cli.php: CLI routes
  • controllers/Luthier.php: Fake controller, necessary to use some routes
  • middleware: Middleware folder

Important: Make sure that your application folder has write permission!

Usage

To add routes, use the static methods of the Route class:

<?php
# application/routes/web.php

// This points to 'baz' method of 'bar' controller at '/foo' path under a GET request:
Route::get('foo', '[email protected]');

// To add a route parameter, enclose with curly brackets {}
Route::get('blog/{slug}', '[email protected]');

// To make a parameter optional, add a ? just before closing the curly brackets
// (Luthier CI will make all the fallback routes for you)
Route::get('categories/{primary?}/{secondary?}/{filter?}', '[email protected]');

// The (:any) and (:num) CodeIgniter route placeholders are available to use, with this syntax:
Route::get('cars/{num:id}/{any:registration}', '[email protected]');

// Custom regex? it's possible with this syntax:
Route::post('main/{((es|en)):_locale}/about', '[email protected]');

Use the Route::cli() method to add command line routes. All CLI routes must be inside routes/cli.php file. This is an example of a CLI route:

Route::cli('path','[email protected]');

The ci() function returns the framework instance, acting as a virtual controller. This is useful if you use callbacks as routes:

Route::get('foo', function(){
    ci()->load->view('some_view');
});

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

Route::get('company/about_us', '[email protected]')->name('about_us');

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

<a href="<?= route('about_us');?>">My link!</a>
// <a href="http://example.com/company/about_us">Link</a>

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

<?= 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.)

// Prefix only
Route::group('prefix', function(){
    Route::get('bar','[email protected]');
    Route::get('baz','[email protected]');
});

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

Middleware

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

# Route middleware:
Route::put('foo/bar','[email protected]', ['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
# application/middleware/TestMiddleware.php

class TestMiddleware
{
    public function run()
    {
        // (Entry point)
    }
}

Documentation

Visit the project official website (disponible en español)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].