Skip to content

Instantly share code, notes, and snippets.

@fprochazka
Created August 30, 2013 22:11
Show Gist options
  • Select an option

  • Save fprochazka/6394804 to your computer and use it in GitHub Desktop.

Select an option

Save fprochazka/6394804 to your computer and use it in GitHub Desktop.
<?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);
}
$params['action'] = 'show';
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;
}
),
'id' => array(
Route::FILTER_OUT => function ($id) {
return str_replace('%3B', ';', rawurlencode($id));
}
),
'presenter' => 'Virtualnepohladnice',
'action' => 'show',
));
$router[] = new Route('[<locale [a-z]{2}>/]<presenter>/<action>[/<id>]', 'Homepage:default');
return $router;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment