Cakephp 3.6 Routing => get dynamic Patterns from db


#1

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

exampe

posts/berlin
posts/paris
posts/madrid ,…

we have routing
posts/title-slug
posts/a-z0-1
posts/postType

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.


#2

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?


#3

@Zuluru

Thanks,

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.


#4

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


#5

@Graziel Thanks, I know that