0

Is it possible to create magic route with nette route ?

what i mean of magic route is i dont need to declare any route array on routelist... but when i type address on browser address bar such as : http:somesite.com/product/detail/123.

it would point to presenter product -- renderDetail (this magic route is known in other framework, and i think for some reason it would make complicated if i would type every single action/presenter redirection on routelist array)

thanks in advance.

navotera
  • 321
  • 1
  • 15

2 Answers2

4

Do you mean $router[] = new Route('<presenter>/<action>[/<id>]', 'Homepage:default');? It's in the documentation: https://doc.nette.org/en/2.3/routing#toc-route.

Matěj Koubík
  • 1,087
  • 1
  • 9
  • 25
  • yes its on documentation.. but it does not make magic route .. when im point url to SomeControllerAction it wont load that SomeController except i type the route in routelist array. – navotera Apr 13 '16 at 01:42
1

Route from Matěj is working. You just need to type SomePresenter::actionTwoWords as some/two-words in url.

But don't construct urls by hand, use {link} macro in latte templates or Nette\Application\LinkGenerator in code.

Tomáš Jacík
  • 645
  • 4
  • 12
  • what matej sugget that i need to type all my presenter action to route.. yes it would works but it would not called magic route, but manual route.... by the way. – navotera Apr 18 '16 at 00:53
  • If you asking if Nette will work without routes at all, it will not. You need to have at least one route defined. That's why this basic route, which acts like you want I think, is present in sandbox: https://github.com/nette/sandbox – Tomáš Jacík Apr 19 '16 at 06:31