i try something like:
$app = new Slim();
$app->get("/home", function() use($app) {
//some query for sub pages
$my_sub_page = 'subpage';
$app->get("/home/" . $my_sub_page, function() use($app) {
//
});
});
but the result of www.site.com/home/subpage is 404...
is possible to do something like this?
I miss something?
Thanks.
Use http://docs.slimframework.com/#Route-Groups
<?php
$app = new \Slim\Slim();
// API group
$app->group('/api', function () use ($app) {
// Library group
$app->group('/library', function () use ($app) {
// Get book with ID
$app->get('/books/:id', function ($id) {
});
// Update book with ID
$app->put('/books/:id', function ($id) {
});
// Delete book with ID
$app->delete('/books/:id', function ($id) {
});
});
});
You probably want to use route parameters:
$app->get("/home/:mysubpage", function($mysubpage) use($app) {
//do something with $mysubpage
//it contains the value of www.site.com/home/{whatever-you-put-here}
});
This helps you to get dynamic routes with arbitrary arguments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With