Cakephp 3.6 Routing => get dynamic Patterns from db

I have task to retrieve data based on location / city list in db.


posts/madrid ,…

we have routing

And our SEO chef have nice :thinking: new idea, find posts by city names, where city list ist dynamic (city must have more than 3 posts).

Any idea.

Run a process periodically to find all such city names and cache them somewhere that the routing initialization can read from, then add them all in a foreach? Any chance they’d be okay with a different URL structure like posts/from/paris or just from/paris?



i have same idea about background process.

no our routing is posts/{here-come-various-type-of-slug/inclusive-subslug}

I have now one other idea, store all patterns in db and slugs in db.

you might use TableRegistry anywhere even in routes.php ie.

$citiesTable = \Cake\ORM\TableRegistry::getTableLocator()->get('Cities');
$topCities = $citiesTable->find('top')->all();

note that using only city name can be potentially colliding - cities with same names but it depends on your dataset

@Graziel Thanks, I know that