luyadev / luya

LUYA is a scalable web framework and content management system with the goal to please developers, clients and users alike.
https://luya.io
MIT License
811 stars 205 forks source link

Wrong url in layout context #2013

Closed boehsermoe closed 1 year ago

boehsermoe commented 4 years ago

What steps will reproduce the problem?

Using Url::toRoute(['/crawler/default/index']) inside the layout file will generate "domain.com/crawler/default/index" correctly on start/root page. But on subpages like "domain.com/contact" wrong url will be generated "domain.com/contact/default/index"

What is the expected result?

Url::toRoute(['/crawler/default/index']) should generated the same URL on subpages too.

nadar commented 4 years ago

and crawler is the module name in the config i assume?

boehsermoe commented 4 years ago

Yes it is.

nadar commented 4 years ago

When using CMS, you should use https://luya.io/api/luya-cms-helpers-Url to link to the page which includes the module. But maybe we can fix it somehow. Need to make unit tests for this case

boehsermoe commented 4 years ago

I think the problem ist here -> https://github.com/luyadev/luya/blob/4e5a9db3a869f289c2af15406252dd0a4078e95b/core/web/UrlManager.php#L381

$isOutgoingModulePage is false because the current navitem is the cms page and not a Module Page -> https://github.com/luyadev/luya/blob/4e5a9db3a869f289c2af15406252dd0a4078e95b/core/web/UrlManager.php#L368

Maybe the UrlHelper need a option or function to generate url with out navitem context.

nadar commented 4 years ago

Try this: https://github.com/luyadev/luya/blob/master/core/helpers/Url.php#L47-L54

maybe this needs better documentation

nadar commented 4 years ago

Does that fixed the issue?

boehsermoe commented 4 years ago

That it's, thank you!

boehsermoe commented 4 years ago

I got the same problem in cms module context with the captcha image url. In \yii\captcha\Captcha::run the Html::img will called which use the Url::to function.

The captcha widget is used in a module context block under /contact. The generated url for the image is /contact/captcha and not /site/captcha

nadar commented 4 years ago

Yes its true, in this case you might define an url rule, so LUYA knows the route and prefix the the current cms page correctly.

nadar commented 1 year ago

I am going to close this issue because:

If you think this is still important or there are more/new informations. Please reopen the issue and let us know.

If this is a problem or a feature you like to discuss, join our discussion: LUYA discussions. We try to keep our issue tracker as clean as possible in order to focus on active issues.