I am using the php flight framework: http://flightphp.com/ I want to call flight::route(); a few time to automatically create a few routers. But i need a variable in the callback function.
I'm trying:
foreach($pages as $page) {
Flight::route("/" . $page['route'], function() {
// I need $page here
});
}
Flight::start();
Where $pages is an array of objects I created. And I need those objects when the route is triggered. How do I do this?
Maybe somebody can help me with this. The Flightphp framework has a method Flight::set("variable", value) and Flight::get("variable");
Maybe I could do:
foreach($pages as $page) {
Flight::route("/" . $page['route'], function() {
$page = Flight::get("page");
var_dump($page);
// I need $page here
});
Flight::set("page", $page);
}
But this will make me always have the LAST page. While I might like to route to the first or any other page.