Last active
June 14, 2017 08:25
-
-
Save pikl-cz/500cb81615404c8aff3c70a7b6309e97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
use Nette; | |
use Nette\Application\Routers\RouteList; | |
use Nette\Application\Routers\Route; | |
use Nette\Application\Routers\CliRouter; | |
class RouterFactory { | |
/** | |
* @return Nette\Application\IRouter | |
*/ | |
public static function createRouter() { | |
$router = new RouteList; | |
$router[] = $adminRouter = new RouteList('Admin'); | |
$adminRouter[] = new Route('https://%host%/admin/<presenter>/<action>/[<id>]', 'Homepage:default'); | |
$router[] = $shopRouter = new RouteList('Shop'); | |
$actionList = array( | |
'Cart' => array( | |
'kosik' => 'list', | |
'kosik/osobni-informace' => 'personalInfo', | |
'kosik/dopravce-a-platba' => 'transportAndPayment', | |
'kosik/shrnuti' => 'summary', | |
), | |
'Sign' => array( | |
'zakaznik/prihlaseni' => 'in', //Přihlášení | |
'zakaznik/odhlaseni' => 'out', //Odhlášení | |
), | |
'Customer' => array( | |
'zakaznik/detail' => 'detail', //Zákazník detail | |
'zakaznik' => 'default', //Zákazník | |
), | |
'InfoPage' => array( | |
'informace/<url>' => 'detail', // Info stránky | |
'informace' => 'default', // Info stránky | |
), | |
'Product' => array( | |
'produkt/detail/<productUrl>' => 'detail', // Produkt detail | |
), | |
'Homepage' => array( | |
'/' => 'default', | |
), | |
'Category' =>array( | |
'<category>[/<subCategory1>][/<subCategory2>][/<subCategory3>]' => 'list', | |
), | |
); | |
foreach ($actionList as $presenter => $actionList) { | |
self::generateRouteList($presenter, $actionList, $shopRouter); | |
} | |
//$shopRouter[] = new Route('https://%host%/<presenter>/<action>/[<id>]', 'Homepage:default'); | |
return $router; | |
} | |
/* | |
* Funkce pro zjednodušení zápisu rout | |
*/ | |
protected static function generateRouteList($presenter, $list, &$shopRouter) { | |
foreach ($list as $mask => $action) | |
{ | |
$shopRouter[] = new Route($mask, array( | |
'presenter' => $presenter, | |
'action' => $action | |
) | |
); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment