slim/light

This package is abandoned and no longer maintained. No replacement package was suggested.

Enhance Slim framework lightly.

0.1.1 2014-02-04 15:09 UTC

This package is not auto-updated.

Last update: 2022-03-28 18:30:19 UTC


README

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.