vlucas / bulletphp

A resource-oriented micro PHP framework
http://bulletphp.com
BSD 3-Clause "New" or "Revised" License
418 stars 50 forks source link

Just a dumb question #51

Closed entraigas closed 10 years ago

entraigas commented 10 years ago

Yes, I read the docs and it's not there... Lets say I have a blog and I want to fetch all comments from a given article. The URL is something like GET /blog/article/{id}/comments I wonder if this is possible to define an $app->path inside an $app->param. Something like this:

$app->path('blog/articles', function($request) use($app) {

    //GET blog/articles/123
    $app->param('int', function($request, $articleId) use($app) {

        //GET blog/articles/123/comments
        $app->path('comments', function($request) use($app, $articleId) {
            //return all comments from article 123
        }
    }
}
vlucas commented 10 years ago

Yes, absolutely - I do this all the time, like /posts/{id}/edit, etc. but since Bullet parses only one path segment at a time, your routes would have to look like this:

$app->path('blog', function($request) use($app) {
    $app->path('articles', function($request) use($app) {

        //GET blog/articles/123
        $app->param('int', function($request, $articleId) use($app) {

            //GET blog/articles/123/comments
            $app->path('comments', function($request) use($app, $articleId) {
                //return all comments from article 123
            });
        });
    });
});
entraigas commented 10 years ago

Thank you!! I'm starting to build a small web system using Bullet.

vlucas commented 10 years ago

Good luck, and let me know if you need help with any other questions! :)