geniv/nette-alias-router

Database alias router extension for Nette Framework

v3.1.7 2019-05-11 16:31 UTC

README

Installation

$ composer require geniv/nette-alias-router

or

"geniv/nette-alias-router": "^3.1"

require:

"php": ">=7.0",
"nette/application": ">=2.4",
"nette/caching": ">=2.5",
"nette/di": ">=2.4",
"nette/http": ">=2.4",
"nette/neon": ">=2.4",
"nette/utils": ">=2.4",
"latte/latte": ">=2.4",
"tracy/tracy": ">=2.4",
"dibi/dibi": ">=3.0",
"geniv/nette-locale": ">=2.0"

Include in application

available source drivers:

  • ArrayDriver (array)
  • NeonDriver ()
  • DibiDriver (dibi + cache _AliasRouter-DibiDriver)

In router alias is not good idea change last alias, but insert new alias with new datetime stamp.

neon configure:

route:
    cs:
        "staticky-slug": "Homepage:pokus"
        "staticky-slug1": "Homepage:pokus2"
    en:
        "static-slu": "Homepage:pokus"
        "static-slug1": "Homepage:pokus2"


# alias router
aliasRouter:
#   debugger: true
#   autowired: true
#    driver: AliasRouter\Drivers\ArrayDriver(%route%)
#    driver: AliasRouter\Drivers\NeonDriver(%appDir%/router.neon)
    driver: AliasRouter\Drivers\DibiDriver(%tablePrefix%)
#   enabled: true
#   domainAlias:
#       example.cz: cs
#       example.com: en
#       example.de: de

neon configure extension:

extensions:
    aliasRouter: AliasRouter\Bridges\Nette\Extension

Available interface: IAliasRouter

RouterFactory.php:

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

usage @layout.latte:

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

manual create or delete:

use AliasRouter\Drivers\IDriver;
$this->context->getByType(IDriver::class)->deleteRouter('Homepage', 'default');
$this->context->getByType(IDriver::class)->createRouter('Homepage', 'default', 'muj alias');
$this->context->getByType(IDriver::class)->createRouter('Homepage', 'default', 'muj alias XX', ['locale' => 'en']);