V
V
Vlad Osadchyi2019-12-19 11:04:20
Yii
Vlad Osadchyi, 2019-12-19 11:04:20

Why is the URL not generated in yii2?

Rule in urlManager:

'<language:(ru|en)>/profile/<action:[\w-]+>/<entity_id:\d+>/<entity_name:.+>' => 'profile/default/<action>',


Output URL:
Url::to(['/profile',
        'language' => 'ru',
        'action' => 'club',
        'entity_id' => 45,
        'entity_name' => 'Juv']);


Expectation:
en/profile/club/45/Juventus


Result:
/profile?language=en&action=user&entity_id=45&entity_name=Juv


UPD:
For this rule, you need to form the URL like this:
Url::to(['/profile/default/' . $action,
            'language' => LanguageService::getCurrentKey(),
            'entity_id' => $model->id,
            'entity_name' => $model->getNameForSharing()], $scheme);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2019-12-19
Tokarczuk @Kewa2008

urlManager is configured correctly?

'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
              ....
             ],
            ]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question