Welcome Guest, Not a member yet? Register   Sign In
Luthier-CI: Improved routing + middleware for CodeIgniter 3
#1

(This post was last modified: 05-13-2018, 07:03 PM by andersonsalas.)

Hi!

I want to share my recently rewritten project: it's called Luthier-CI.

What is Luthier-CI?

Luthier-CI is a CodeIgniter plugin that enables Laravel-like routing and introduces the concept of Middleware in our applications.

Key features
  • Clean and easy installation via hooks
  • Global and per-route middleware
  • Advanced routing: prefixes, namespaces, anonymous functions as routes, route groups, cli routes, named parameters, optional parameters, sticky parameters

With Luthier-CI we can, for example, write this:
 
PHP Code:
Route::group('catalog', function(){
 
   Route::get('cars/{category_id}/{filter_by?}''CarsController@catalog');
 
   Route::match(['get','post'], 'bikes/{category_id}/{filter_by?}''BikesController@catalog');
 
   Route::get('airplanes/{category_id}/{filter_by?}''AirplanesController@catalog');
});

Route::post('this/is/a/{very?}/{large?}/{route?}/{example?}''TestController@foo'); 

Instead this:
 
PHP Code:
$route['catalog/cars/(:any)']['GET'] = 'CarsController/catalog/$1';
$route['catalog/cars/(:any)/(:any)']['GET'] = 'CarsController/catalog/$1/$2';
$route['catalog/bikes/(:any)']['GET'] = 'BikesController/catalog/$1';
$route['catalog/bikes/(:any)']['POST'] = 'BikesController/catalog/$1';
$route['catalog/bikes/(:any)/(:any)']['GET'] = 'BikesController/catalog/$1/$2';
$route['catalog/bikes/(:any)/(:any)']['POST'] = 'BikesController/catalog/$1/$2';
$route['catalog/airplanes/(:any)']['GET'] = 'AirplanesController/catalog/$1/$2';
$route['catalog/airplanes/(:any)/(:any)']['GET'] = 'AirplanesController/catalog/$1/$2';
$route['this/is/a']['GET'] = 'TestController/foo';
$route['this/is/a/(:any)']['POST'] = 'TestController/foo/$1';
$route['this/is/a/(:any)/(:any)']['POST'] = 'TestController/foo/$1/$2';
$route['this/is/a/(:any)/(:any)/(:any)']['POST'] = 'TestController/foo/$1/$2/$3';
$route['this/is/a/(:any)/(:any)/(:any)/(:any)']['POST'] = 'TestController/foo/$1/$2/$3/$4'
 
... or use an anonymous function instead a controller:

PHP Code:
Route::get('test', function(){
 
   echo 'Hello world!';
}); 

... or even perform the same action with all routes using a middleware:

PHP Code:
Route::middleware(function(){
 
   echo 'This will be executed on every route below!';
}, 
'pre_controller');

Route::group('foo', function(){
 
   Route::get('bar', function(){
 
       echo 'Test';
 
   });
 
   Route::get('baz', function(){
 
       echo 'Test 2';
 
   }, ['middleware' => ['Auth']]); # Only this route will run the 'Auth' middleware!
}); 

More information (Documentation, installation instructions, etc.)

View Luthier-CI on GitHub

It is a somewhat complex project so any suggestion, opinion, or even donation is welcome!

Tested in PHP 5/7 and CodeIgniter 3.1.7 / 3.1.8 (apparently everything works  Big Grin )
Reply
#2

[Update 13-05-2018]

The 0.2.1 version was released recently. Improvements accumulated to date:
  • Full CLI routing support: laravel-like syntax now works with CLI commands, and a few built-in CLI commands are available to use (controller creation, migration wizard, etc.)
  • Better late than never, but we published an official project website with more detailed documentation and examples:Luthier-CI documentation

More features on the way  Big Grin
Reply
#3

Wonderful work! Thanks!
Reply
#4
Smile 

[Update 25-06-2018]

Version 0.3.0 Released! it comes with new features:

  1. Built-in auth system: now you can easily implement an user login/signup in your application thanks to SimpleAuth, a cool ready-to-use authentication template. For advanced users is also available the Luthier CI Authentication Framework, a structure to build authentication systems from scratch.
  2. PHP Debug Bar integration (experimental) : a basic integration with this debug tool was added, and now you can log variables, expressions, database queries, and handle with custom data collectors.

Screenshots:

[Image: simpleauth_login_screenshot.png]
SimpleAuth default login screen

[Image: luthier-ci-debugbar.png]
PHP Debug Bar integration

Thanks for your comments, we appreciate all of them  Smile

Github: Luthier CI
Documentation: Luthier CI Documentation
Reply
#5
Photo 

I am trying to work with Luthier-CI and I must say that I really like the routing part. I have a question about the middleware part.

How do I pass variables to a route? I'd like to see something possible like:

Code:
Route::get('toystory/woody/{category_id}', 'moviesController@cast', [
       'middleware' => [
           'Input' => [
               'search'   => false,
               'userId'   => [],
               'language' => 'DE',
               'age'      => [
                   'sanitizer' => FILTER_SANITIZE_NUMBER_INT,
                   'default'   => 23
               ],
               'start'    => 0,
               'limit'    => 50
           ]
       ]
   ]);

But I don't want to have the arguments in the controller. So my question is, is this possible?

When I do it like above I get always the message: "Unable to find .php in your application/middleware folder".
Reply
#6

This is awesome !!!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB