Closed nikiedev closed 5 months ago
The way I found to solve this is as follow:
$admin = new AdminController();
Flight::route('GET /admin/articles/@id', function($id) use ($admin) {
$admin->articles($id);
});
But seems to be useful if there is a way to do it directly. Maybe
Flight::route('GET /admin/articles/@id', [$admin, 'articles', $id]);
Flight collects queries only by the standard format (?query=example). Anything else used in the URI in the standard format (ex. admin/articles/1) is part of the route.
So if you need it as an argument in the route, use @masakik's solution above.
I'd suggest you simplify it though:
// notice the (/@id) which allows you to run all routes here
Flight::route('GET|POST /admin/articles(/@id)', function($id) {
$admin = new AdminController();
$admin->articles($id); // id = X || null
});
Hi! I am sending data from Controller to View via GET|POST settings in router. Well, here is my Router:
as you see, i have a method in controller:
When i make query like this:
/admin/articles?id=1
all works fine, but when the query looks like the next one:/admin/articles/1
i don't get data from Flight::request()->query Can someone help me please to solve the problem?I made a temporary solution (in htaccess):
RewriteRule ^admin/articles/(\w+)$ /admin/articles?id=$1
but, may be there is a better way?