Admin area - Save config

Update at 2017-12-22 09:08:20


Introduce

CI Base has a built-in module setting, which allows you to perform some installation of information on your application. Currently, CI Base is using 3 configuration information

  1. Logo
  2. Turns off member registration
  3. Default member role when member is registered

If you need more settings information such as: Site name, referring to the web page, contact email, hot phone number, ... you can also easily

Use

The document will guide you how to create a configuration information to save "contact email".

Before you create this configuration information, the document will only tell you the following 3 things

  1. The contact email will have the configuration name "email_contact"
  2. Contact emails will have the namespace "config"
  3. Contact Email is configuration information that is automatically loaded with the system

The first thing we have is the html form as follows:

<!-- send to /admin.php/api/setting/save with method POST -->

<div class="form-group">
    <label class="col-sm-2">
        Contact to email
    </label>
    <div class="col-sm-10">
        <input type="hidden" name="config[setting][email_contact][autoload]" value="1">
        <input type="text" name="config[setting][email_contact][value]" value="" />
    </div>
</div>

In the above form you can see that we have 2 inputs

  1. config [xxx] [autoload]: Indicates that this configuration information will be loaded automatically with the system.
  2. config [xxx] [value]: Indicates the value of configuration information

You only need to send the above structure to /admin.php/api/setting/save with the POST method, and how CI Base organizes it.

Note: For a configuration information, there must always be two fields associated with autoload and value

General structure

The general structure of the outgoing configuration data can be written as json as follows

{
    "config": {
        "namespace_1": {
            "config_name": {
                "value": "Value",
                "autoload": 1 // 1 or 0 <=> true or fase
            },
            "config_name1": {
                "value": "Value",
                "autoload": 1 // 1 or 0 <=> true or fase
            }
        },
        "namespace_2": {
            "config_name": {
                "value": "Value",
                "autoload": 1 // 1 or 0 <=> true or fase
            },
            "config_name1": {
                "value": "Value",
                "autoload": 1 // 1 or 0 <=> true or fase
            }
        }
    }
}

In the form of html input

<input type="hidden" name="config[namespace_1][config_name_1][autoload]" value="1" />
<input type="hidden" name="config[namespace_1][config_name_1][value]" value="Value" />
<input type="hidden" name="config[namespace_1][config_name_2][autoload]" value="1" />
<input type="hidden" name="config[namespace_1][config_name_2][value]" value="Value" />

<input type="hidden" name="config[namespace_2][config_name_1][autoload]" value="1" />
<input type="hidden" name="config[namespace_2][config_name_1][value]" value="Value" />
<input type="hidden" name="config[namespace_2][config_name_2][autoload]" value="1" />
<input type="hidden" name="config[namespace_2][config_name_2][value]" value="Value" />