J
J
JohnDaniels2019-01-31 11:29:09
Yii
JohnDaniels, 2019-01-31 11:29:09

How to properly organize routing in this case?

If, for example, there are such routes:
site.ru/moscow - city selection
site.ru/user1 - user's page
site.ru/newsitem - detailed view of news
site.ru/page - some page (with dynamic slug)
different pages , but in urlManager for all these pages the rule will be the same.
how to properly scatter them over different controller/action ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Bukharev, 2019-01-31
@evgenybuckharev

If you organize the routes in this way, then the load on the urlManager will not be small, since each rule will have to check for the presence of a particular news, the presence of a particular user, and you will also have to control the uniqueness of the slug for each entity.
Therefore, it is better to abandon such a routing scheme, and add
your own individual features to the routes for individual entities, for example:

site.ru/c/moscow - выбор города
site.ru/u/user1 - страница пользователя
site.ru/n/newsitem - детальный просмотр новости
site.ru/p/page - какая-нибудь страница (с динамическим slug)

M
Maxim Timofeev, 2019-01-31
@webinar

I completely agree with Evgeny Bukharev , I will add 1 more option from
site.ru/city_moscow
site.ru/user_1
site.ru/news_antonina-ela-ovosh
site.ru/page_about
But you will have to write your own urlManager, and wait for additional problems with project growth. So they use the site.ru/city/moscow classics more often. Plus it's RESTful.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question