Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTunde Adegoroye
20,597 PointsUsing rewrite rules with get and rendering
Just wondering since we use this to get a value within the string when we load the page
$app->get('/hello/:name', function ($name) {
echo "Hello, $name";
});
How could could we set get variables in a link like this below and change it to something like cars/100
<a href="cars?id=100">Link</a>
so using the slim framework we could easily just retrieve the value from the cars page like so
$app->get('/cars/:id', function ($id) {
echo "You've chosen, $id";
});
was maybe hoping someone could offer some insight or if i'm going the wrong way about it was thinking we'd might have to use rewrite rules but i have no idea about writing them
2 Answers
thomascawthorn
22,986 PointsIf you're in control of how the link is printed, could you not do something like this?
<a href="cars/100">Link</a>
Michael Soileau
9,431 PointsThat's possible, but more in-depth than what has been covered thus far. That's where Twig comes in, which takes the variables passed in by Slim from the route and binds them to parameters in your output.