Skip to content

aigdonia/Slim-Light

 
 

Repository files navigation

Slim-Light

Enhance Slim framework lightly.

Features

Separate Routing

If you have a lot of very long view functions to route, your code may look very messy:

$app->get('/:id', function() use ($app) {
  // do somethings...
})
->name('get_book_by_id')
->conditions(array('id' => '\d+'));

$app->post('/:id', function() use ($app) {
  // do somethings...
})
->name('edit_book_by_id')
->conditions(array('id' => '\d+'));

$app->delete('/:id', function() use ($app) {
  // do somethings...
})
->name('remove_book_by_id')
->conditions(array('id' => '\d+'));

// Other view functions go on...

Being confused by all these tails? In Slim-Light you can just separate routing and view funtions registering:

// Routing
$app->route('get_book_by_id', '/int:id', 'GET');  // Setup all small tails in one place!
$app->route('edit_book_by_id', '/int:id', 'POST');
$app->route('remove_book_by_id', '/int:id', 'DELETE');

// Registering
$app->set('get_book_by_id', function ($id) use ($app) {
  // do somethings...
});
$app->set('edit_book_by_id', function ($id) use ($app) {
  // do somethings...
});
$app->set('remove_book_by_id', function ($id) use ($app) {
  // do somethings...
});

Class Based Resource

Tried of writing restful like API? Resource object can ease you pain:

class MovieResource extends \Slim\Light\ResourceController
{
    public function get($id) {
        echo $id;
    }

    public function update($id) {
        echo $id;
    }

    public function remove($id) {
        echo $id;
    }

    public function get_all() {
        echo 'All movies.';
    }

    public function create() {
        echo 'Create a movie.';
    }
}

// Setup all in one line!
$app->resource('movie', '/movie', new MovieResource());

Contribution

Feel free to open an issue! Waiting for your pull request <3

License

MIT, head over LICENSE for more informations.

About

Enhance Slim framework lightly.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 99.7%
  • Makefile 0.3%