Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use Nette\Application\Routers\RouteList,
- Nette\Application\Routers\Route,
- Nette\Application\Routers\SimpleRouter;
- use Nette\Utils\Strings;
- /**
- * Router factory.
- */
- class RouterFactory
- {
- /**
- * @return Nette\Application\IRouter
- */
- public function createRouter(\Nette\Database\SelectionFactory $db)
- {
- $router = new RouteList();
- $router[] = new Route('index.php', 'Homepage:default', Route::ONE_WAY);
- //$router[] = new Route('[<locale=sk sk|en>/]<presenter>/<action>[/<id>]', 'Homepage:default');
- $router[] = new Route('[<locale [a-z]{2}>/]virtualne-pohladnice', 'Virtualnepohladnice:default');
- $router[] = new Route('[<locale [a-z]{2}>/][!<action virtualne-pohladnice|virtual-postcards>]/<id>', array(
- NULL => array (
- Route::FILTER_IN => function ($params) use ($db) {
- if (!is_numeric($params['id'])) {
- @list($id, $name) = explode(';', $params['id']);
- $params['id'] = intval($id);
- }
- return $params;
- },
- Route::FILTER_OUT => function($params) use ($db) {
- if (!empty($params['id']) && is_numeric($params['id'])){
- /** @var $pages \Nette\Database\Table\Selection */
- $pages = $db->table('cardCategories')->get($params['id']);
- if ($pages === false) {
- $params['id'] = 1;
- } else {
- $params['id'] = $params['id'] . ';'. Strings::webalize($pages->{'name_'.$params['locale']});
- }
- }
- if ($params['locale'] === 'en') {
- $params['action'] = 'virtual-postcards';
- } else {
- $params['action'] = 'virtualne-pohladnice';
- }
- return $params;
- }
- ),
- 'presenter' => 'Virtualnepohladnice',
- 'action' => 'show'
- ));
- $router[] = new Route('[<locale [a-z]{2}>/]<presenter>/<action>[/<id>]', 'Homepage:default');
- return $router;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment