PHPackages                             olajideolamide/ci4-settings - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. olajideolamide/ci4-settings

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

olajideolamide/ci4-settings
===========================

Application settings and feature flags library for CodeIgniter 4

v1.1.0(8mo ago)101MITPHPPHP ^8.0

Since Dec 8Pushed 8mo agoCompare

[ Source](https://github.com/olajideolamide/ci4-settings)[ Packagist](https://packagist.org/packages/olajideolamide/ci4-settings)[ RSS](/packages/olajideolamide-ci4-settings/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (1)Versions (5)Used By (0)

  ![Logo for laravel-activitylog](docs/screenshots/banner.png)CodeIgniter 4 Settings &amp; Feature Flags Library
==================================================

[](#codeigniter-4-settings--feature-flags-library)

[![Latest Version on Packagist](https://camo.githubusercontent.com/fa48c955c94c9d99573f942c7c88660241fb76af2ad92d2d73a243edf90c1ebf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f6c616a6964656f6c616d6964652f6369342d73657474696e67732e737667)](https://packagist.org/packages/olajideolamide/ci4-settings)[![GitHub License](https://camo.githubusercontent.com/c8f70823018ac86deec4397aa1812e5175e63bbb94e45eda4e26bf29be72b670/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6f6c616a6964656f6c616d6964652f6369342d73657474696e6773)](https://camo.githubusercontent.com/c8f70823018ac86deec4397aa1812e5175e63bbb94e45eda4e26bf29be72b670/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6f6c616a6964656f6c616d6964652f6369342d73657474696e6773)

Database-backed application settings and feature flags for CodeIgniter 4, with dot-notation support, automatic type casting, and optional caching.

This package gives you a simple `settings()` helper and a small `Settings` library so you can store configuration in the database instead of hard-coding everything in config files.

---

Features
--------

[](#features)

- Database-backed settings using a dedicated `settings` table
- Feature flags via a simple `feature('flag_name')` helper
- Dot-notation keys like `app.name`, `mail.smtp.host`, etc.
- Automatic type detection &amp; casting
    - `bool`, `int`, `float`, `string`, `json` (arrays/objects)
- Nested settings &amp; JSON
    - Store arrays/objects and access them via dot notation
- Optional caching via CodeIgniter’s cache system
- Convenience helpers
    - `settings()` – get/set/delete settings
    - `feature()` – check if a feature flag is enabled
- Smart delete
    - Can remove nested keys from JSON settings (e.g. remove `app.mail.host` from a stored `app.mail` JSON blob)

---

Requirements
------------

[](#requirements)

- PHP **8.0+**
- CodeIgniter **4.x**
- A database supported by CodeIgniter 4

---

Installation
------------

[](#installation)

### 1. Install via Composer

[](#1-install-via-composer)

```
composer require olajideolamide/ci4-settings
```

### 2. Register the namespace (if needed)

[](#2-register-the-namespace-if-needed)

In most Composer-based CodeIgniter 4 apps, Composer’s autoloader is already wired up.
If you are using modules and explicit namespaces, add the package namespace to `app/Config/Autoload.php`:

```
// app/Config/Autoload.php

public $psr4 = [
    APP_NAMESPACE => APPPATH,
    'Config'      => APPPATH . 'Config',

    // Add this line (keep your existing entries)
    'Jide\Settings' => ROOTPATH . 'vendor/olajideolamide/ci4-settings/src',
];
```

### 3. Run the migration

[](#3-run-the-migration)

This package ships with a migration that creates the `settings` table.

Run:

```
php spark migrate -n Jide\Settings
```

This will create a table named `settings` with columns:

- `id` (INT, PK, auto-increment)
- `key` (VARCHAR, unique)
- `value` (TEXT)
- `type` (VARCHAR – `string`, `bool`, `int`, `float`, `json`, etc.)
- `group` (VARCHAR, nullable) – optional grouping for your own use
- `is_feature` (TINYINT(1)) – marks a setting as a feature flag
- `created_at`, `updated_at` (DATETIME, nullable)

### 4. Load the helper

[](#4-load-the-helper)

To use the `settings()` and `feature()` helpers, load the helper:

**Per controller / per use:**

```
helper('settings');
```

**Globally (recommended):**

In `app/Config/Autoload.php`:

```
public $helpers = ['settings'];
```

Or in a base controller:

```
protected $helpers = ['settings'];
```

---

Quick Start
-----------

[](#quick-start)

Once installed, migrated, and the helper is loaded, you can start using it immediately.

### Get a setting

[](#get-a-setting)

```
// Get 'app.name', return 'My App' if it doesn't exist
$appName = settings('app.name', 'My App');
```

### Set a setting

[](#set-a-setting)

```
// Using the helper to get the library instance
settings()->set('app.name', 'My Awesome App');
```

### Check if a setting exists

[](#check-if-a-setting-exists)

```
if (settings()->has('app.name')) {
    // do something
}
```

### Delete a setting

[](#delete-a-setting)

```
settings()->delete('app.name');
```

### Access all settings

[](#access-all-settings)

```
$config = settings()->all(); // returns nested array of all settings
```

---

Feature Flags
-------------

[](#feature-flags)

Feature flags make it easy to toggle functionality on or off without redeploying code.

### Enable a feature flag

[](#enable-a-feature-flag)

Feature flags are stored as keys under the `feature.` namespace, for example: `feature.new_checkout`.

```
// Create or update a feature flag
settings()->set(
    'feature.new_checkout',
    true,                // value
    'checkout',          // optional group
    true                 // is_feature = true
);
```

### Check if a feature is enabled (helper)

[](#check-if-a-feature-is-enabled-helper)

```
if (feature('new_checkout')) {
    // show new checkout flow
} else {
    // fallback to old flow
}
```

You can also pass the full key:

```
if (feature('feature.new_checkout')) {
    // also works
}
```

### Check with a default value

[](#check-with-a-default-value)

```
if (feature('beta_banner', false)) {
    // only runs if explicitly enabled
}
```

Under the hood, `feature('something')`:

- Ensures the key is prefixed with `feature.` if you didn’t add it
- Reads the setting
- Casts it to a boolean using common truthy representations: `1`, `true`, `yes`, `on` (case-insensitive)

---

Dot-Notation &amp; Nested Settings
----------------------------------

[](#dot-notation--nested-settings)

This library supports **dot-notation** for keys, and can store arrays/objects as JSON.

### Storing a nested array

[](#storing-a-nested-array)

```
settings()->set('mail', [
    'host'       => 'smtp.example.com',
    'port'       => 587,
    'encryption' => 'tls',
    'username'   => 'user@example.com',
    'password'   => 'secret',
]);
```

Internally this is saved as:

- `key` = `mail`
- `type` = `json`
- `value` = JSON encoding of the array

### Reading nested values

[](#reading-nested-values)

```
$host = settings('mail.host');       // "smtp.example.com"
$port = settings('mail.port');       // 587 (int)
$enc  = settings('mail.encryption'); // "tls"
```

### Updating part of a JSON setting

[](#updating-part-of-a-json-setting)

You can overwrite the whole array:

```
settings()->set('mail', [
    'host' => 'smtp2.example.com',
] + settings('mail', []));
```

Or add nested configuration piece by piece using a more granular key:

```
$config = settings()->all(); // or build what you need

// For example, to create a grouped "app" config
settings()->set('app', [
    'name' => 'My App',
    'mail' => [
        'host' => 'smtp.example.com',
    ],
]);

// Later, read:
$host = settings('app.mail.host');
```

When JSON values are loaded, they are decoded into arrays and merged into the full settings structure so that dot-paths like `app.mail.host` work as expected.

---

Type Handling
-------------

[](#type-handling)

The library automatically detects and casts types based on the value you set.

### Detection

[](#detection)

When you call `set($key, $value, ...)`, the library determines:

- `bool` → stored as `'1'` or `'0'`, returned as `bool`
- `int` → stored as string, returned as `int`
- `float` → stored as string, returned as `float`
- `array` / `object` → stored as JSON (`type = json`), returned as array
- anything else → stored and returned as `string`

### Casting on read

[](#casting-on-read)

When you call `get()` or `settings('key')`:

- If `type = bool` it’s converted using a liberal boolean parser:
    - `1`, `true`, `yes`, `on` → `true`
    - Anything else → `false`
- If `type = int` → `(int)$value`
- If `type = float` → `(float)$value`
- If `type = json` → `json_decode()` to an array
- Otherwise → raw string

---

Settings Helper &amp; Library API
---------------------------------

[](#settings-helper--library-api)

### `settings(?string $key = null, mixed $default = null)`

[](#settingsstring-key--null-mixed-default--null)

- If **no key** is passed (`settings()`):
    - Returns an instance of `Jide\Settings\Libraries\Settings`
- If **a key** is passed (`settings('app.name')`):
    - Returns the setting value (typed) or `$default` if not found

**Examples:**

```
// Get instance
$settings = settings();

// Get value
$appName = settings('app.name', 'My App');

// Chain methods
settings()->set('app.name', 'My App');
```

### `feature(string $flag, bool $default = false): bool`

[](#featurestring-flag-bool-default--false-bool)

Convenience wrapper around `Settings::featureEnabled()`.

- Accepts either `new_checkout` or `feature.new_checkout`
- Returns `bool`

---

### `Jide\Settings\Libraries\Settings` methods

[](#jidesettingslibrariessettings-methods)

If you prefer to work with the library directly:

```
use Jide\Settings\Libraries\Settings;

$settings = new Settings(); // uses default config and model
```

Available methods:

- `get(string $key, $default = null): mixed`
    Get a setting by key (supports dot notation).
- `set(string $key, $value, ?string $group = null, bool $isFeature = false): bool`
    Create or update a setting.
- `all(): array`
    Get all settings as a nested array.
- `has(string $key): bool`
    Check if a setting exists (supports dot notation).
- `delete(string $key): bool`
    Delete a setting by key.
    Also attempts to remove nested keys from JSON parent entries (e.g. `app.mail.host` inside `app.mail`).
- `featureEnabled(string $flag, bool $default = false): bool`
    Check if a feature flag is enabled.

---

Caching
-------

[](#caching)

This library uses a small config class to control caching:

```
// Jide\Settings\Config\Settings

public string $table    = 'settings';
public bool   $useCache = true;
public int    $cacheTTL = 600;        // seconds
public string $cacheKey = 'ci4_settings';
```

By default:

- All settings are cached in memory on first request
- If CodeIgniter’s `cache()` function is available and `$useCache` is `true`:
    - The settings array is stored under `$cacheKey` for `$cacheTTL` seconds
- Any `set()` or `delete()` call automatically clears the cache

If you want to customise these values at runtime, you can instantiate the library with your own config:

```
use Jide\Settings\Config\Settings as SettingsConfig;
use Jide\Settings\Libraries\Settings;

// Create custom config
$config = new SettingsConfig();
$config->useCache = false;
$config->cacheTTL = 0;
$config->table    = 'app_settings'; // if you also customised the migration

$settings = new Settings($config);
```

> Note: the `helper('settings')` uses `new Settings()` with the **default** config.
> If you need a customised config, create your own `Settings` instance as above.

---

Building an Admin UI (Optional)
-------------------------------

[](#building-an-admin-ui-optional)

The table contains extra metadata to help you build an admin/settings UI:

- `group` – group related settings (e.g. `mail`, `app`, `billing`)
- `is_feature` – mark which rows are feature flags so you can list them separately

Example: only list feature flags:

```
use Jide\Settings\Models\SettingModel;

$model = new SettingModel();

$flags = $model
    ->where('is_feature', 1)
    ->orderBy('key', 'ASC')
    ->findAll();
```

---

License
-------

[](#license)

This project is open-source software licensed under the [MIT license](LICENSE).

---

Author
------

[](#author)

**Olanrewaju “Jide” Olajide**

- Package: `olajideolamide/ci4-settings`
- PRs, issues and suggestions are welcome!

###  Health Score

30

—

LowBetter than 61% of packages

Maintenance60

Regular maintenance activity

Popularity3

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

251d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4281821?v=4)[Olanrewaju Olajide](/maintainers/olajideolamide)[@olajideolamide](https://github.com/olajideolamide)

---

Top Contributors

[![olajideolamide](https://avatars.githubusercontent.com/u/4281821?v=4)](https://github.com/olajideolamide "olajideolamide (16 commits)")[![olajidesaru887](https://avatars.githubusercontent.com/u/223236376?v=4)](https://github.com/olajidesaru887 "olajidesaru887 (2 commits)")

### Embed Badge

![Health badge](/badges/olajideolamide-ci4-settings/health.svg)

```
[![Health](https://phpackages.com/badges/olajideolamide-ci4-settings/health.svg)](https://phpackages.com/packages/olajideolamide-ci4-settings)
```

###  Alternatives

[codeigniter4/appstarter

CodeIgniter4 starter app

1811.8M](/packages/codeigniter4-appstarter)[abydahana/aksara

Aksara is a modern, developer-friendly framework and CMS built on CodeIgniter 4, featuring rapid CRUD development, modular architecture, smart routing, flexible access control, API integration, and an AI assistant to make content management faster and smarter.

1141.2k](/packages/abydahana-aksara)[hermawan/codeigniter4-datatables

Serverside Datatables library for CodeIgniter4

10949.8k4](/packages/hermawan-codeigniter4-datatables)[jason-napolitano/codeigniter4-cart-module

A basic port of the codeigniter 3 cart module for CodeIgniter 4.

5915.6k](/packages/jason-napolitano-codeigniter4-cart-module)[maniaba/asset-connect

AssetConnect is a file management library for CodeIgniter 4 that allows you to associate files with any entity in your application

1016.0k](/packages/maniaba-asset-connect)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
