Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Add random token_salt to config.php
  • Hi guys,

    currently i'm working on an simple installer.

    All things works as espected, only the token_salt in the app/config/config.php can't be updated
    with an random token.

    I tried it with Config::load() and Config::save().

    In the first test, it overwrites the complete config.php.
    In the second test, it overwrites nothing.

    You can find the controller here:

    My workaround is currently to inform the user on the finish view, that he/she has to set the token_salt manually.

    My question is: Is it possible to save a random token_salt in the config.php with the given OOB functionality?

    Thanks a lot.

    Greets
    Marcus 
  • HarroHarro
    Accepted Answer
    I see no reason why you can't load the 'config' config, change it, and save it again. Yes, it will replace the complete file, that is what save does. But from a functional point of view that should not matter.

    If you want to replace a single line and don't touch all others, you'll have to write your own parser that is able to find the correct line and replace the value. That will not be simple.

    Also, your crypt code is wrong. Check the _init() method of the Crypt class on how to generate the correct crypto keys.
  • Hi,

    thanks for your feedback.

    I have updated the installer and using now the same functionality as in the Crypt Class.


    Because of the "problem" with the token_salt in the config.php, i think currently it's okay
    to set it manually.

    Thanks a lot Harro for the fast answer.


    Greets
    Marcus
  • Not sure what the problem is. Losing the comments in config.php? Other than that, I don't see any issue with saving an updated config.

    You can also save your changes to the environment config folder (like you do with db), that will override the global config in app/config.
  • Overwrites the environment config file the complete app config file or only the defined keys?
  • It doesn't overwrite, it merges, both for config and for lang files.

    In order of importance (low -> high):
    - fuel/core
    - packages
    - fuel/app
    - current module (if present)

    And for config, for each of these locations, both the global config, and the environment specific one.

    So assuming no packages and no module, it will load fuel/core/config/config.php, merge it with fuel/app/config/config.php, and merges that with fuel/app/config/<environment>/config.php.

    And it uses Arr::merge(), so it merges on a per-key basis.

    It allows you for example to make a global config for email, then per environment override it with a different mail server address.
  • Hi,
    i tested it with the following:
    \Config::load(\Fuel::$env.'/config', 'env_config', true);
    \Config::set('env_config.security.token_salt',\Security::generate_token());
    \Config::load(\Fuel::$env.'/config', 'env_config');


    But it does not create the config.php in my environment folder.

    The database.php will be created and it uses the same code...

    //get environment specific database config
    \Config::load(\Fuel::$env.'/db', 'database', true);

    //set the database information
    \Config::set('database.default.connection.dsn', 'mysql:host='.\Input::post('db_host').';dbname='.\Input::post('db_name'));
    \Config::set('database.default.connection.username', \Input::post('db_username'));
    \Config::set('database.default.connection.password', \Input::post('db_password'));

    // save the database config
    \Config::save(\Fuel::$env.'/db', 'database');


    For me it looks good. 
     Thanks.
  • HarroHarro
    Accepted Answer
    perhaps use save(), instead of load, set and load again?
  • Oh!

    Thanks! So stupid :D

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion