luya icon indicating copy to clipboard operation
luya copied to clipboard

Wrong url in layout context

Open boehsermoe opened this issue 6 years ago • 9 comments

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.

boehsermoe avatar Apr 18 '20 07:04 boehsermoe

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

nadar avatar Apr 18 '20 11:04 nadar

Yes it is.

boehsermoe avatar Apr 20 '20 17:04 boehsermoe

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

nadar avatar Apr 21 '20 07:04 nadar

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.

boehsermoe avatar Apr 21 '20 09:04 boehsermoe

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

maybe this needs better documentation

nadar avatar Apr 21 '20 09:04 nadar

Does that fixed the issue?

nadar avatar Apr 23 '20 11:04 nadar

That it's, thank you!

boehsermoe avatar Apr 23 '20 17:04 boehsermoe

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

boehsermoe avatar May 16 '20 14:05 boehsermoe

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 avatar May 18 '20 08:05 nadar

I am going to close this issue because:

  • Its a question (Please post questions at LUYA discussions)
  • Missing information's
  • No more activity
  • No one picked up the task (no Pull Request received)

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.

nadar avatar Nov 09 '22 10:11 nadar