How can I include ID in URL using Slim Framework?

I’m new to using SLIM framework, I’m working on a project/platform that allows users to post their listings and take bookings from potential clients. But I want them to be able to share a link to their listing.

I have provided the relevant code below, that is used to display all these listings on a single page. When clicking on one of the listings, the information is pushed into a modal. I’m looking to generate a link for each listing that can be shared via email or message and accessed easily. How can I include the listing ID in the URL?

At the minute I’m stuck with:

localhost/listings

My desired outcome is:

localhost/listings/+id/

Listings.html

function listingInfo($id,$location){


// Detail View Specific


$('.listing-info-container').addClass('active');

$('.listing-info').html('').removeClass('active');

showLoader($('.listing-info'));

showLoader($('.listings-results'));


setTimeout(function(){

$.ajax({

  method: "GET",

  url: "/listing_information/"+$id

  })

.done(function(result){

 $('.listing-info').html(result).addClass('active');

 hideLoader($('.listing-info'));

 hideLoader($('.listings-results'));
 
// hide map if on mobile - link to external google maps site instead

 $('.listings-map').toggleClass('is-hidden', isMobile());
 
// set co-ord vals in hidden textbox
 
$('#listing-detail-directions-ll').val($location.toString().replace(/["'()]/g,'').replace(' ', ''));

 });

}, 1000);

Listings.php:

// to display all listings on a single page

$app->get('/listings', function ($request, $response, $args) {

$variables['title'] = 'Listings';

$variables['categories'] = $this->db->select('listing_categories','*');

return $this->view->render( $response, 'listings.html', $variables,);
});

I think this is what you are looking for.

Then you can generate the URL (assuming you have a route for it) with the path_for function.