Only <id> in primary route

Notice: This thread is very old.
nanuqcz
Member | 822
+
0
-

Hello,
I am trying to create routes that works like this:

Examples for links to articles:

  • /about
  • /contact
  • /pricing

Examples for anything else except articles:

  • /presenter/action/id

I tried this routes

$router = new RouteList();
$router[] = new Route('[/<id>]', array(
	'presenter' => 'Article',
	'action' => 'detail',
	'id' => 'homepage',
));
$router[] = new Route('<presenter>/<action>[/<id>]', 'Homepage:default');
return $router;

but it doesn't work: {link Article:detail, id => 'about'} generates '/article/detail/about' instead of '/about'.

Thanks for answers.
(Nette dev-master)

llsm
Member | 121
+
0
-

Tested in nette 2.2.2

$router[] = new Route('<id>', array(
			'presenter' => 'Article',
			'action' => 'detail',
			'id' => NULL
		));

But beware, this route catches everything like base sandbox route (every page without own route before this one ends with #404), so you have to use it wisely ; )
If you need to use other way, you have to define values of ids to match:

$router[] = new Route('<id>', array(
			'presenter' => 'Article',
			'action' => 'default',
			'id' => array(
				Route::FILTER_STRICT => true,
				Route::FILTER_TABLE => array(
					'test' => 'test'
				)
			)
		));

		$router[] = new Route('<presenter>/<action>[/<id>]', 'Homepage:default');

If this doesnt meet your needs, than you have to write your own router probably

Last edited by llsm (2014-07-04 10:47)