Ich habe kleine Anwendung basierend auf Nette Framework.Wie bekomme ich Werte aus neon Datei in Nette?
Ich habe erstellt constants.neon
Datei und fügen Sie es in den Container. Es wird einige Daten geben, die von Referenten, Modellen, Formularen usw. verfügbar sein sollten.
Wie kann ich auf Werte in constants.neon
zugreifen?
Ich weiß, dass es eine Methode (new \Nette\Neon\Neon())->decode([NEON_FILE_PATH])
gibt, aber ich denke nicht, dass dies die right way
ist. Ich vermute, dass nach der Verwendung von addConfig(...)
in bootstrap.php
alle Daten von diesen Konfigurationsdateien über das ganze System verfügbar sein sollten.
<?php
// bootstrap.php
require __DIR__ . '/../vendor/autoload.php';
$configurator = new Nette\Configurator;
$configurator->setDebugMode(true); // enable for your remote IP
$configurator->enableDebugger(__DIR__ . '/../log');
$configurator->setTempDirectory(__DIR__ . '/../temp');
$configurator->createRobotLoader()
->addDirectory(__DIR__)
->addDirectory(__DIR__ . '/../vendor/phpoffice/phpexcel')
->register();
$configurator->addConfig(__DIR__ . '/config/config.neon');
$configurator->addConfig(__DIR__ . '/config/config.local.neon');
$configurator->addConfig(__DIR__ . '/config/constants.neon');
$container = $configurator->createContainer();
return $container;
Meine constants.neon
Datei:
constants:
DP_OPT = 'DP'
PP_OPT = 'PP'
DV_OPT = 'DV'
ZM_OPT = 'ZM'
TP_OPT = 'TP'
Dank
UPDATE # 1
herausgefunden, dass ich falsch Format .neon
Datei verwendet haben.
constants:
DP_OPT: DP
PP_OPT: PP
DV_OPT: DV
ZM_OPT: ZM
TP_OPT: TP
Danke, das funktioniert gut für mich! BTW ist es möglich, das gleiche Ergebnis zu erhalten, aber 'custom.neon' Datei verwenden, die Container von' addConfig() 'hinzugefügt wird? – tsg
Dies sollte mit jeder Datei funktionieren, solange Sie sie dem Container hinzufügen. –