V
V
Vladislav2020-06-28 10:44:24
Yii
Vladislav, 2020-06-28 10:44:24

Why doesn't urlManager work correctly with modules?

There is a module: panel

There is such a link: And these rules:
Url::to(['panel/order', 'slug' => $service->code])

'panel/order/<slug:\w+>/' => 'panel/order',
'panel/order/<slug:\w+>' => 'panel/order',


When following the link, manually entering the address:
site.ru/panel/order/slug - все ОК работает.

And url::to generates
http://site.ru/panel/panel/order?slug=queue-qwe

this for me: OrderController has this path: Everything is ok in the action too:
namespace app\modules\panel\controllers;
public function actionIndex($slug)
    {
        $service_model = Services::find()->where(['code' => $slug])->one();
        return $this->render('index', compact('service_model'));
    }


What could be the problem ? Why does it not generate a normal link
If you write like this?
<?= Url::to(['/../panel/order', 'slug' => $service->code]) ?>

It generates a normal link, without the second word panel.
But not the CNC, it turns out such a link:
site.ru/panel/order?slug=queue-qwe
and it should be
site.ru/panel/order/queue-qwe

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tim, 2020-06-28
@cr1gger

The hyphen is not specified in the regular expression

'panel/order/<slug:[\w-]+>/' => 'panel/order',
    'panel/order/<slug:[\w-]+>' => 'panel/order',

And the module is accessed like this:
Url::to(['/panel/order', 'slug' => $service->code])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question