把一个slu into变成一个id

I am quite new to Symfony and Doctrine and I'm trying to work out how I can get the following route to convert to an id so I don't have to search by strings all the time (unless that is considered to be fine these days?)

So for example I want /my_app/category/subcategory/page to be readable by my controller as /my_app/3/2/1 so I can use ->find($id) instead of having to use -findBySlug($slug).

How do I do this?

In your routing file:

your_route_name:
    pattern: /my_app/{category}/{subcategory}/{page}
    defaults: { _controller: YourBundle:YourController:FindPost }

In your controller:

public function FindPostAction($category, $subcategory, $page)
{
    //...use $category, $subcategory, $page here
}