Sylnois
Sylnois

Reputation: 1631

Load data from config file with value from config file

I have a config.ini file with some values. One of them is the path to the root of my script. So in my js file i get the content from the config.ini file, but i have one big mistake. To load the data from the config file i already need one value from the config file, namely the path to the config file.

Any idea how to handle that?

Regards Sylnois

Edit:

This is my htaccess:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}  -d

RewriteRule  ^.*$  -  [L]

RewriteRule ^([^/]+)/$  index.php?token=$1 [L]

This rewrites my link from http://domain.com/fun/bla/index.php?token?123 to http://domain.com/fun/bla/123/ .. So if someone access the second link, my js script would not be run anymore, cause i work with relative paths. I have now a value in my config which points to the root directory of my applicatoin: "./fun/bla/". Everything works so fine. But my requirement are, that no paths should be implemented in my code.

Upvotes: 0

Views: 385

Answers (3)

Husman
Husman

Reputation: 6909

This is a chicken and egg problem. The config file cannot contain the path to the config file, its path needs to be known to all parts of the program that need to know the settings. Perhaps have the path as a global variable in your program somewhere?

Upvotes: 0

Aurelia Peters
Aurelia Peters

Reputation: 2209

What I've always done is to statically define the name of the config file in my code, so in your JS:

config_file = '/path/to/myconfig.ini'

Upvotes: 0

Colin M
Colin M

Reputation: 13348

Yes. Store the path to your config file in code. The rest can be loaded from the config file.

You can't possibly have everything in a config file. I once worked with someone who tried to store database configuration in the database. And then realized their mistake when they tried to make the application, you know, work.

Upvotes: 2

Related Questions