Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Modified the Config library so that an array of items can be set using set_item() #1189

wants to merge 1 commit into from

3 participants


I was not sure if we should be testing for empty values in the array, but the original version doesn't, so I left it as-is.


I personally would rather see this as a new set_items() method. What do others think?


I dont think that set_items() is consistent with the rest of core.


What if you want to actually set an item to be an array? This change would break it.

@narfbg narfbg closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 14, 2012
  1. @JonoB

    Modified the Config library so that an array of items can be set usin…

    JonoB authored
    …g the set->item() method.
This page is out of date. Refresh to see the latest.
19 system/core/Config.php
@@ -320,13 +320,26 @@ public function system_url()
* Set a config file item
- * @param string the config item key
+ * An array can optionally be passed as the first parameter, in which
+ * case each item in the array will be added to the config
+ *
+ * @param mixed the config item key
* @param string the config item value
* @return void
- public function set_item($item, $value)
+ public function set_item($item, $value = '')
- $this->config[$item] = $value;
+ if (is_array($item))
+ {
+ foreach ($item as $key => $value)
+ {
+ $this->set_item($key, $value);
+ }
+ }
+ else
+ {
+ $this->config[$item] = $value;
+ }
// --------------------------------------------------------------------
1  user_guide_src/source/changelog.rst
@@ -86,6 +86,7 @@ Release Date: Not Released
- Added function set_data() to Form_validation library, which can be used in place of the default $_POST array.
- Added function reset_validation() to form validation library, which resets internal validation variables in case of multiple validation routines.
- Changed the Session library to select only one row when using database sessions.
+ - Modified the Config library so that an array of items can be set using the set->item() method.
- Core
7 user_guide_src/source/libraries/config.rst
@@ -119,6 +119,13 @@ one, you can do so using::
Where item_name is the $config array index you want to change, and
item_value is its value.
+You can also set an array of items as follows::
+ $items = array(
+ 'first_item' => 'first_item_value,
+ 'second_item' => 'second_item_value,
+ );
+ $this->config->set_item($items);
.. _config-environments:
Something went wrong with that request. Please try again.