M
M
Mikhail Vasiltsev2018-06-28 20:47:51
Yii
Mikhail Vasiltsev, 2018-06-28 20:47:51

Can several different actions coexist on the same url format?

Greetings web developers. Here's the thing. I am using the YII2 framework. There are 2 different actions that render different page types and work
with different models. But I want the url to have the same format. Therefore, in web.php, in the routing section, I prescribe the following rules:

'<alias:[\w-]+>' => 'controller/action1',
'<alias:[\w-]+>' => 'controller/action2',

Alias ​​is a field in the database for an entity that is responsible for a beautiful url.
Well, I get a completely expected situation - the rule that is higher interrupts the lower one, as a result, site.ru/alias opens from the first action, but not from the second, because according to the routing rule, it does not get into its own action, but into the first one, which, of course, does not find such an alias, since it works with a completely different model/table and generally with different logic.
I don’t know what to do with all this, are there any solutions how to fit 2 or even more actions on one url format?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Arman, 2018-06-28
@Arik

You can implement your own class of rules , at least the first one, if the logic does not fit this rule, then return false, where the second route will catch

K
kupurim, 2018-06-28
@kupurim

Create a table with aliams and their relationship to the desired actions.

D
davidnum95, 2018-06-28
@davidnum95

'<alias:[\w-]+>' => 'controller/<alias>',

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question