external config file for homepresenter

5 months ago

kolaloka
Member | 60
+
0
-

I need to create an external config file where a web admin can change some variables. I do not know how to set the /path/to/my/config/

Also where to put it and how to use the variables in presenter functions?
My idea is something like this:

config.php:

<?php
$ds = something;
$identity1 = something_else;
$identity2 = something_else;
$password = secretpassword;
?>

HomePresenter.php:

<?php
...
include /path/to/my/config/config.php

private function connectionOne{
$bind = ldap_bind($ds, $identity1, $password);
}

private function connectionTwo{
$bind = ldap_bind($ds, $identity2, $password);
}
...
?>

Please, help.

5 months ago

CZechBoY
Member | 3130
+
0
-

You can save these variables into database and fetch them when needed.

5 months ago

kolaloka
Member | 60
+
+1
-

Unfortunately not. They want a plain file to be able to configure themselves. Can nette do that?

5 months ago

CZechBoY
Member | 3130
+
+1
-

OK, then you can use neon file, or php script or other format…
Only thing you should do is to load that configuration file(s) in bootstrap.php [https://doc.nette.org/….4/bootstrap#…]
like this

$configurator->addConfig('config.neon');

And put there some parameters
like this

parameters:
    ldap:
        user: xxx
        password: yyy
        host: abc

For more info read the whole DIC page https://doc.nette.org/…cy-injection

Last edited by CZechBoY (2018-06-04 10:27)

5 months ago

kolaloka
Member | 60
+
0
-

OK, I understand now. Thank you very much!