Wrong URL for n:href pointing to Module

Notice: This thread is very old.
Tauras
Member | 3
+
0
-

Hello,

I am new to the framework, but find it really good! :)

I have an issue with n:href pointing to modules. A link is set in global menu and included in @layout.latte.

<a n:href="MyModule:MyPresenter:MyRenderer">Test</a>

Outside the Module (mysite.com/OtherModule), this link is generated correctly (points to mysite.com/mymod/MyPresenter/MyRenderer). However when you are inside the module (mysite.com/mymod), it generates error:

<a href="error: Cannot load presenter 'MyModule:MyModule:MyRenderer',
 class 'MyModuleModule\MyModuleModule\MyRendererPresenter' was not found in
 '/webroot/app/MyModuleModule/MyModuleModule/presenters/MyRendererPresenter.php'.">Test</a>

Router setup is

$container->router[] = $myModuleRouter = new RouteList('MyModule');
$myModuleRouter[] = new Route('mymod/', 'MyPresenter:MyRenderer');
$myModuleRouter[] = new Route('mymod/<action>[/<id>]', 'MyPresenter:<action>');
$myModuleRouter[] = new Route('mymod/<presenter>/<action>[/<id>]');

Nette version: latest git master: b8c66eab6

duke
Member | 650
+
0
-

The problem is that you have specified the target MyModule:MyPresenter:MyRenderer using relative notation. Either use absolute notation, i.e. :MyModule:MyPresenter:MyRenderer (notice the leading colon) or omit the MyModule: prefix while you are within MyModule module, i.e. MyPresenter:MyRenderer.

Tauras
Member | 3
+
0
-

Thank you duke,

Your solution worked properly, however a little note on inconsistency.

When you generate a link to renderer in module use

<a n:href=":ModuleName:PresenterName:ActionName">

All names start with colon.

However Router does not follow this convention.

$container->router[] = $myModuleRouter = new RouteList('MyModule');
$myModuleRouter[] = new Route('mymod[/<presenter>][/<action>][/<id>]', ':MyModule:MyPresenter:MyAction');

should logically work, but it does not. Correct way is declaring route as following:

$container->router[] = $myModuleRouter = new RouteList('MyModule');
$myModuleRouter[] = new Route('mymod[/<presenter>][/<action>][/<id>]', 'MyPresenter:MyAction');

Is it a bug?

Vojtěch Dobeš
Gold Partner | 1316
+
0
-

It is not a bug, module is set in constructor of RouteList, therefore it is not included in subroutes.

David Grudl
Nette Core | 8218
+
0
-

Is it something like namespace in PHP. It is not possible to use <?php namespace \A;.