All Projects → davinder17s → Codeigniter Middleware

davinder17s / Codeigniter Middleware

Simplest yet powerful middleware library for codeigniter, can be used to make routes login only, apply roles and permission system, modify, intercept or preprocess requests.

Projects that are alternatives of or similar to Codeigniter Middleware

Micro Xrce Dds Client
Micro XRCE-DDS Client repository
Stars: ✭ 30 (-30.23%)
Mutual labels:  middleware
Nex
Aiming to simplify the construction of JSON API service
Stars: ✭ 35 (-18.6%)
Mutual labels:  middleware
Connect Gzip Static
connect middleware for statically compressed files
Stars: ✭ 39 (-9.3%)
Mutual labels:  middleware
Graphql Upload
Middleware and an Upload scalar to add support for GraphQL multipart requests (file uploads via queries and mutations) to various GoLang GraphQL servers
Stars: ✭ 32 (-25.58%)
Mutual labels:  middleware
Copper
Copper is a set of Go packages that help you build backend APIs quickly and with less boilerplate.
Stars: ✭ 35 (-18.6%)
Mutual labels:  middleware
Redux Json Router
Declarative, Redux-first routing for React/Redux browser applications.
Stars: ✭ 37 (-13.95%)
Mutual labels:  middleware
Adroit
ADR/PSR-7 middleware
Stars: ✭ 28 (-34.88%)
Mutual labels:  middleware
School Website
School website for SMK (Senior High School) and built with Codeigniter 3
Stars: ✭ 42 (-2.33%)
Mutual labels:  codeigniter
Htmlcache
Laravel middleware to cache the rendered html
Stars: ✭ 35 (-18.6%)
Mutual labels:  middleware
Asp.net Core Graphql Middleware
ASP.Net Core GraphQL Middleware
Stars: ✭ 38 (-11.63%)
Mutual labels:  middleware
Grocery Crud
Grocery CRUD is a PHP Codeigniter Framework library that creates a full functional CRUD system without the requirement of extra customisation to the JavaScripts or the CSS to do it so.
Stars: ✭ 962 (+2137.21%)
Mutual labels:  codeigniter
Sos
Sandia OpenSHMEM is an implementation of the OpenSHMEM specification over multiple Networking APIs, including Portals 4, the Open Fabric Interface (OFI), and UCX. Please click on the Wiki tab for help with building and using SOS.
Stars: ✭ 34 (-20.93%)
Mutual labels:  middleware
Slim Cli
A Slim 3 middleware enabling a mock HTTP request to be made through the CLI.
Stars: ✭ 37 (-13.95%)
Mutual labels:  middleware
Apicache
Simple API-caching middleware for Express/Node.
Stars: ✭ 957 (+2125.58%)
Mutual labels:  middleware
Codeigniter Psr4 Autoload
CodeIgniter 3 PSR-4 Autoloader for Application
Stars: ✭ 40 (-6.98%)
Mutual labels:  codeigniter
Whoops
PSR-15 middleware to use Whoops as error handler
Stars: ✭ 29 (-32.56%)
Mutual labels:  middleware
Codeigniter Restserver Test
A temporary repository for testing https://github.com/chriskacerguis/codeigniter-restserver
Stars: ✭ 35 (-18.6%)
Mutual labels:  codeigniter
Wretch Middlewares
Collection of middlewares for the Wretch library. 🎁
Stars: ✭ 42 (-2.33%)
Mutual labels:  middleware
Znetcs.aspnetcore.authentication.basic
A simple basic authentication middleware.
Stars: ✭ 40 (-6.98%)
Mutual labels:  middleware
Webpack Isomorphic Dev Middleware
The webpack-dev-middleware, but for isomorphic applications
Stars: ✭ 38 (-11.63%)
Mutual labels:  middleware

Codeigniter Middlewares

This library enables you to quickly add any middleware to your codeigniter application and in too few lines you get everything up and running smoothly. Tested on CodeIgniter 3.0.4, should work on 2.2+ as well

Update: Still working flawlessly as of May 2019

Quick Integration Guide

  • Copy MY_Controller.php to application/core
  • In your controller extend MY_Controller instead of CI_Controller
  • Create your middleware class in middleware directory and add function run()
  • Create a function middleware() and return array of middlewares to run
  • That's it.
Create your middlewares directory
  • Create new middlewares directory in application if not exists.
Create your class in application/middlewares
<?php
// src: application/middlewares/AdminAuthMiddleware.php

// Extends nothing, it's upto you what you want to extend. Completely generic.
class AdminAuthMiddleware {
    // Get injected controller and ci references
    protected $controller;
    protected $ci;
    
    // Some custom and example data related to this class
    public $roles = array();
    
    // All middlewares will pass controller and ci class objects as references to constructor
    // It's upto you, that what you do with them
    // Obviously it's not required :)
    
    public function __construct($controller, $ci)
    {
        $this->controller = $controller;
        $this->ci = $ci;
    }
    
    // This function is required, and is entry point to this class
    public function run(){
        // you can reference to current controller called class
        $this->controller->some_your_method();
        
        // you can run db queries
        $categories = $this->ci->db->get('categories');
        
        // you can get reference to models, libraries
        $users = $this->controller->user->list();
        $this->controller->load->library('session');
        
        // you can get session references
        $email = $this->ci->session->userdata('email');
    
        // you can modify the class and add your methods to this class
        $this->roles = array('somehting', 'view', 'edit');
        
        // you can get reference to called function and class name on request
        $this->controller->router->method; // returns method name, eg. index
        $this->controller->router->class; // returns from which class (controller class) this function has been called
        
        // and also you can terminate the request, if you dont want it to pass on
        show_error('You are not allowed to perform this operation');
    }
}
Extend MY_Controller class
<?php
// src: application/controllers/Home.php

class Home extends MY_Controller 
{
    // only create if you want to use, not compulsory.
    // or return parent::middleware(); if you want to keep.
    // or return empty array() and no middleware will run.
    protected function middleware()
    {
        /**
         * Return the list of middlewares you want to be applied,
         * Here is list of some valid options
         *
         * admin_auth                    // As used below, simplest, will be applied to all
         * someother|except:index,list   // This will be only applied to posts()
         * yet_another_one|only:index    // This will be only applied to index()
         **/
        return array('admin_auth', 'someother|except:index,list', 'yet_another_one|only:index');
    }
    
    // Middlewares applied according to above code: admin_auth, yet_another_one
    public function index()
    {
        // you can also use the middleware class's object later if you wish.
        var_dump($this->middlewares['admin_auth']);
        
        $this->load->view('index');
    }
    
    // Middlewares applied according to above code: admin_auth, someother
    public function posts()
    {
        $this->load->view('posts_view');
    }
    
    // Middlewares applied according to above code: admin_auth
    public function list()
    {
        $this->load->view('something');
    }
}

Notes:

Class name require Middleware as suffix, also cannot contain, underscores or hyphens Here is list of some valid conventions:

  • admin => AdminMiddleware
  • Admin => AdminMiddleware
  • SomeThing => SomeThingMiddleware
  • some_lazy_name => SomeLazyNameMiddleware
  • some_OtHer_Crazy_name => SomeOtHerCrazyNameMiddleware
  • hell_Yeah => HellYeahMiddleware

On the left side is name of middleware, and on the right side is class name and .php filename for the class. Above list explains, how your middleware name would resolve to a class name.

That's all, I hope documentation and code was helpful. Cheers!

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].