A
A
alex4answ2019-03-11 16:52:02
Yii
alex4answ, 2019-03-11 16:52:02

Url to generates links not from the site root?

Good afternoon, there is a link:
<a href="<?=Url::to(['site/news'])?>">Новости</a>
and there is a urlManager rule:

'<action:(login|register|news)>' => 'site/<action>'

And while I'm in the site (default) controller, everything is fine, the links are generated in the form:
/news But for example, if I
go to the admin module, the link starts to look like
/admin/site/news
this:
/news
links are generated in breadcrumbs, in the menu not relative to the root of the site, but relative to the current url, it even reached:
profile/news/news/news/news (if you follow the link)
How to deal with this, and what I'm doing wrong ?
PS For some reason, the @web and @webroot aliases do not exist for me (basic version, set by composer)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artyom Mishin, 2019-03-13
@kerneldos

You need to explicitly specify what you want relative to the site root, like this:
<a href="<?=Url::to(['/site/news'])?>">Новости</a>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question