Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Edit values in config file
  • i have this array in the config file:
    'organization' =>array(
    'name' => 'example name',
    'address' => 'example street,
    'country' => 'Lebanon',
    'city' => 'Saida',
    'countryID' => '120',
    'legal_entity' => 'S.A.L',
    'default_pricing' => '(Default)',
    'default_pricing_ID' => '1',
    'default_warehouse_id' => 1,
    'email' => 'info@example.com',
    'website' => 'www.example.com',
    'phone' => '03 254526',
    'logo' => 'assets/img/Settings/LOGO.png',
    ),

    and i am trying to edit it from my website using this funciton, but it is not changing anything and not giving me an error:

    \Config::load('organization', 'foo');
                            
                                \Config::set('foo.name',\Input::param('name',''));
                                    
                                \Config::set('foo.address',\Input::param('address',''));
                                    
                                \Config::set('foo.city',\Input::param('city',''));
                                    
                                \Config::set('foo.country',\Input::param('country',''));
                                    
                                \Config::set('foo.email',\Input::param('email',''));
                                    
                                \Config::set('foo.phone',\Input::param('phone',''));
                                    
                                \Config::set('foo.website',\Input::param('website',''));
                            
                            
                            \Config::save('organization', 'foo');


    please help me if you can, thank you!!
  • HarroHarro
    Accepted Answer
    What is that file called?

    Assuming, based on your load statement that file is called "organisation.php". So if you load that, you'll end up with:

    'organisation' => array(      // name of the config file
        'organisation' => array(  // name of your array
            ...
        ),
    )

    So you need to use \Config::set('foo.organisation.name', ....);

    Second point is that when you save, config files are written to the environment folder, so to ./config/development or ./config/production, and not to ./config. Files in ./config should only contain defaults for all environments.

    When you load it, both config files will be read and merged.
  • hii thank you for your time , im sorry for the late reply,

    but the organisation array i have is in the original config file not in development or production, but i think that i need to put the array in the development or production file so i can change the values right ??
  • It doesn't matter.

    Files in app/config are global, for all environments, and can't be written to. Files in app/config/<env> are specific to that environment, and can be written to.

    If a config file exists in both, the will be merged when read, with the environment specific values overriding the global values.

    If you write a config file, it will always be written to the environment directory, even if it was read from a global config file.

    Having said that, adding application specific data in config;.php (which is your framework configuration) is a bad idea, it will make upgrading difficult. It is better to create a separate application.php (or whatever name) config file for those values.

    And if your data is in config.php, you have misunderstood the way Config works.

    \Config::load('configuration', 'foo')

    loads a config file with the name configuration.php. The framework config, in config.php, is always loaded when the framework starts, it needs its own configuration.

    var_dump(\Config::get('configuration'));

    will show you that. And you can change it with

    \Config::set('organisation.website', 'http://new.example.com');

    at runtime. But you can't write it, as it is in the global config which you haven't loaded. 

    So create a new config file called "organisation.php". In it, add

        return array(
            'name' => 'example name',
            'address' => 'example street,
            'country' => 'Lebanon',
            'city' => 'Saida',
            'countryID' => '120',
            'legal_entity' => 'S.A.L',
            'default_pricing' => '(Default)',
            'default_pricing_ID' => '1',
            'default_warehouse_id' => 1,
            'email' => 'info@example.com',
            'website' => 'www.example.com',
            'phone' => '03 254526',
            'logo' => 'assets/img/Settings/LOGO.png',
        );

    Load it using

    \Config::load('organisation', true);

    Access it using

    $website = \Config::get('organisation.website');

    Write it using

    \Config::set('organisation.website', $website);

    And save it using

    \Config::save('organisation', 'organisation');

Howdy, Stranger!

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

In this Discussion