Guest User

Untitled

a guest
Aug 30th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  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 (
  27. Route::FILTER_IN => function ($id) use ($db) {
  28. if (is_numeric($id)) {
  29. return $id;
  30. } else {
  31. @list($id, $name) = explode(';', $id);
  32. return intval($id);
  33. }
  34. },
  35. Route::FILTER_OUT => function($id) use ($db) {
  36. if (!is_numeric($id)){
  37. return $id;
  38. }else {
  39. /** @var $pages \Nette\Database\Table\Selection */
  40. $pages = $db->table('cardCategories')->get($id);
  41. if ($pages === false)
  42. return 1;
  43. else
  44. return $id . ';'. Strings::webalize($pages->name_sk);
  45. }
  46. }
  47. ),
  48. 'presenter' => 'Virtualnepohladnice',
  49. 'action' => 'show'
  50. ));
  51.  
  52. $router[] = new Route('[<locale [a-z]{2}>/]<presenter>/<action>[/<id>]', 'Homepage:default');
  53.  
  54. return $router;
  55.  
  56. }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment