View difference between Paste ID: 73t8wmsX and KfQ5tenx
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
			NULL => array (
27
				Route::FILTER_IN => function ($params) use ($db) {
28
					if (!is_numeric($params['id'])) {
29-
						@list($id, $name) = explode(';', $id);
29+
						@list($id, $name) = explode(';', $params['id']);
30
						$params['id'] = intval($id);
31
					}
32
33
					return $params;
34
				},
35
				Route::FILTER_OUT => function($params) use ($db) {
36
					if (is_numeric($params['id'])){
37
						/** @var $pages \Nette\Database\Table\Selection */
38-
						$pages = $db->table('cardCategories')->get($id);
38+
						$pages = $db->table('cardCategories')->get($params['id']);
39
						if ($pages === false) {
40
							$params['id'] = 1;
41
						} else {
42
							$params['id'] = $id . ';'. Strings::webalize($pages->name_sk);
43
						}
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
}