I am trying to create a forum for my website. I have been running into issues with posting data. I planned for it to be so that when the user clicks on a category, it POSTs the category's id so I can then get that id and then list all of the topics under that category id.
$app->get('/showTopic/category/:cat_id', function($cat_id) use($app) {
echo $cat_id;
})->name('showTopic');
$app->post('/showTopic/category/:cat_id', function() use($app) {
$cat_id = $app->request()->post('cat_id');
})->name('showTopic.post');
Now I am only echoing the cat_id
because I want to get this working before I do any thing else.
<a href="{{urlFor('showTopic.post')}}">
This is my anchor tag for creating the link to the page that I will show the topic. However when I click on the link the page just displays :cat_id
whereas is i were to manually change the url to a number it would display that number.
I know how to get the id for the category, I just want to test it with the number 1 for now.
So my big question is how do I pass that number in/what am I doing wrong. Thanks for the help
I don't know if I understand what you're asking, but it seems you want to create an url for the showTopic.post
route . You can add additional parameters to the urlFor
function and set the cat_id
to 1:
<a href="{{urlFor('showTopic.post', {"cat_id": "1"})}}">