View difference between Paste ID: FviZTxPw and 45skR0MQ
SHOW: | | - or go back to the newest paste.
1
<?php
2
3
use Nette\Application\Routers\RouteList,
4
	Nette\Application\Routers\Route,
5
	Nette\Application\Routers\SimpleRouter;
6
use Nette\Utils\Strings;
7
8
9
/**
10
 * Router factory.
11
 */
12
class RouterFactory
13
{
14
15
	/**
16
	 * @return Nette\Application\IRouter
17
	 */
18
	public function createRouter(\Nette\Database\SelectionFactory $db)
19
	{
20
		$router = new RouteList();
21
		$router[] = new Route('index.php', 'Homepage:default', Route::ONE_WAY);
22
		//$router[] = new Route('[<locale=sk sk|en>/]<presenter>/<action>[/<id>]', 'Homepage:default');
23
24
		$router[] = new Route('[<locale [a-z]{2}>/]virtualne-pohladnice', 'Virtualnepohladnice:default');
25
		$router[] = new Route('[<locale [a-z]{2}>/]virtualne-pohladnice/<id>', array(
26-
			'id' => array (
26+
			'NULL' => array (
27-
				Route::FILTER_IN => function ($id) use ($db) {
27+
				Route::FILTER_IN => function ($params) use ($db) {
28-
					if (is_numeric($id)) {
28+
					if (!is_numeric($params['id'])) {
29-
						return $id;
29+
30-
					} else {
30+
						$params['id'] = intval($id);
31
					}
32-
						return intval($id);
32+
33
					return $params;
34
				},
35-
				Route::FILTER_OUT => function($id) use ($db) {
35+
				Route::FILTER_OUT => function($params) use ($db) {
36-
					if (!is_numeric($id)){
36+
					if (is_numeric($params['id'])){
37-
						return $id;
37+
38-
					}else {
38+
39
						if ($pages === false) {
40
							$params['id'] = 1;
41-
						if ($pages === false)
41+
						} else {
42-
							return 1;
42+
							$params['id'] = $id . ';'. Strings::webalize($pages->name_sk);
43-
						else
43+
						}
44-
							return $id . ';'. Strings::webalize($pages->name_sk);
44+
45
46
					return $params;
47
				}
48
			),
49
			'presenter' => 'Virtualnepohladnice',
50
			'action' => 'show'
51
		));
52
53
		$router[] = new Route('[<locale [a-z]{2}>/]<presenter>/<action>[/<id>]', 'Homepage:default');
54
55
		return $router;
56
57
	}
58
59
}