geniv/nette-configurator

Nette 框架的配置器和翻译组件

v4.2.8 2019-03-17 17:05 UTC

README

安装

$ composer require geniv/nette-configurator

"geniv/nette-configurator": "^4.0"

require

"php": ">=7.0",
"nette/nette": ">=2.4",
"dibi/dibi": ">=3.0",
"geniv/nette-locale": ">=2.0",
"geniv/nette-search-content": ">=1.0",
"geniv/nette-translator": ">=2.0"

包含在应用程序中

可用的源驱动器

  • DevNullDriver(默认值)
  • DibiDriver(dibi + cache _Configurator-DibiDriver

自翻译类

  • ConfiguratorTranslator(cache _Configurator-ConfiguratorTranslator

neon 配置

# configurator
configurator:
#   debugger: true
#   autowired: true
#    driver: Configurator\Drivers\DevNullDriver
    driver: Configurator\Drivers\DibiDriver(%tablePrefix%)
    translator: false
#    searchMask: 
#       - *Translation.neon
    searchPath:
        - %appDir%/presenters/AppTranslation.neon
#    excludePath:
#        - CustomExcludeTranslation.neon

neon 配置扩展

extensions:
    configurator: Configurator\Bridges\Nette\Extension

描述

内部组合 id_identid_locale 必须是唯一的!类型内容仅如 "category" 或 "flag of type"

内部数据在组件首次使用时加载。

可用接口: IConfigurator

使用

protected function createComponentConfig(IConfigurator $configurator): IConfigurator
{
    // disable auto create ident
    //$configurator->setAutoCreate(false);
    return $configurator;
}
$this['config']->isEnable('ident'): bool;
$this['config']->getValue('ident'): mixed;

// echo value of ident
$this['config']->renderText('ident');
// return value of ident
$this['config']->renderText('ident', true);

// substitute logic
$this['config']->renderText('ident', null, 'arg');
$this['config']->renderText('ident', null, ['arg']);

// set data like translator
$this['config']->setTranslator('ident', 'text');
$this['config']->setEditor('ident', 'new text');

$this['config']->getDataByIdent('ident');

使用

{control config:text 'web-title'}

{control config:text 'web-title', true}

{control config:text 'web-title', null, 'argument'}
{control config:text 'web-title', null, ['argument']}

<h1 n:if="$presenter['config']->isEnable('web-title')">{control config:text 'web-title'}</h1>

<h1 n:if="$presenter['config']->getValue('show-web-title')">{control config:text 'web-title'}</h1>

{* long equivalent - WHY?!: *}
<h1 n:if="$presenter['config']->renderCheckbox('show-web-title', true)">{control config:text 'web-title'}</h1>