geniv/nette-alias-router

Database alias router extension for Nette Framework

v2.1.7 2018-05-05 16:52 UTC

README

Installation

$ composer require geniv/nette-alias-router

or

"geniv/nette-alias-router": ">=1.0.0"

require:

"php": ">=5.6.0",
"nette/nette": ">=2.4.0",
"dibi/dibi": ">=3.0.0",
"geniv/nette-locale": ">=1.0.0"

Include in application

neon configure:

# alias router
aliasRouter:
#   debugger: true
#   autowired: self
    tablePrefix: %tablePrefix%
#   enabled: true
#   domainSwitch: true
#   domainAlias:
#       example.cz: cs
#       example.com: en
#       example.de: de

neon configure extension:

extensions:
    aliasRouter: AliasRouter\Bridges\Nette\Extension

RouterFactory.php:

public static function createRouter(ILocale $locale, AliasRouter $aliasRouter): IRouter
...
if ($aliasRouter->isEnabled()) {
    $router[] = $aliasRouter;
    $aliasRouter->setDefaultParameters('Homepage', 'default', 'cs');
    $aliasRouter->setPaginatorVariable('visualPaginator-page');
    //$aliasRouter->setSecure(true);
    //$aliasRouter->setOneWay(true);
}

usage @layout.latte:

{if $presenter->context->hasService('aliasRouter.default')}
    {ifset slug}
        {include slug|addSlug}
    {/ifset}
{/if}

manual create or delete:

use AliasRouter\RouterModel;
$this->context->getByType(RouterModel::class)->createRouter('Homepage', 'default', 'muj alias');
$this->context->getByType(RouterModel::class)->deleteRouter('Homepage', 'default');