Resolving module url via \yii\helpers\Url

Hello everyone!

I’ve faced such a problem with generating links for my module views

While being on a page


I try to create link to



Url::toRoute('permissions') // Result is "/rights-manager-dev/roles/permissions"

Try #2

Url::toRoute('/permissions') // Result is "/permissions"

Ok. I dived into the \yii\helper\Url code and discovered, that folowing code solves my problem:

Url::toRoute('permissions/') // Result is "/rights-manager-dev/permissions"

This happens because of \yii\helpers\Url::normalizeRoute($route) protected static function.
I attach an image with explanation

Defining route as “permissions/” looks strange to me.
Is it supposed to be so, when using modules? Or am I missing smth?
How should one use \yii\helpers\Url correctly inside a module?

Thank you!

Route is expected to be controller/action. If you provide slash at the beginning it will be treated as the full route from the root, without slash at the beginning the current module will be the root (and you can see it in your examples). If provided value does not contain slash (as in “between controller and action part”) it’s assumed you are providing only action (so current controller is added by default, also you can see it in your example). When you provide slash at the end it is treated as the action is omitted so the default one will be used.

Looks like I’ve got it. The correct usage should be:


Thank you!