PHPackages                             dgvirtual/codeigniter4-meta-info - 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. [Database &amp; ORM](/categories/database)
4. /
5. dgvirtual/codeigniter4-meta-info

ActiveLibrary[Database &amp; ORM](/categories/database)

dgvirtual/codeigniter4-meta-info
================================

Codeigniter4 library enabling use of Entity-Attribute-Value style storage for additional fields of models.

13PHPCI passing

Since Feb 22Pushed 1y ago1 watchersCompare

[ Source](https://github.com/dgvirtual/codeigniter4-meta-info)[ Packagist](https://packagist.org/packages/dgvirtual/codeigniter4-meta-info)[ RSS](/packages/dgvirtual-codeigniter4-meta-info/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

CodeIgniter4 Meta Info Library
==============================

[](#codeigniter4-meta-info-library)

CodeIgniter4 Meta Info library enables use of Entity-Attribute-Value style storage for additional data of entities used with your models. Library is based on code from [Bonfire2 project](https://github.com/lonnieezell/bonfire2). It allows storing user-configurable bits of information for your project's entity classes without the need to modify those classes.

[![PHPUnit](https://github.com/dgvirtual/codeigniter4-meta-info/actions/workflows/phpunit.yml/badge.svg)](https://github.com/dgvirtual/codeigniter4-meta-info/actions/workflows/phpunit.yml)[![Coverage](https://camo.githubusercontent.com/7a303d663f92e864ec9cec1c15793ded55200845214d7463a9106e3004419536/68747470733a2f2f636f6465636f762e696f2f67682f64677669727475616c2f636f646569676e69746572342d6d6574612d696e666f2f6272616e63682f646576656c6f702f67726170682f62616467652e737667)](https://camo.githubusercontent.com/7a303d663f92e864ec9cec1c15793ded55200845214d7463a9106e3004419536/68747470733a2f2f636f6465636f762e696f2f67682f64677669727475616c2f636f646569676e69746572342d6d6574612d696e666f2f6272616e63682f646576656c6f702f67726170682f62616467652e737667)[![PHPStan](https://github.com/dgvirtual/codeigniter4-meta-info/actions/workflows/phpstan.yml/badge.svg)](https://github.com/dgvirtual/codeigniter4-meta-info/actions/workflows/phpstan.yml)[![PHP](https://camo.githubusercontent.com/d6aac44f81cb2e6f4e71f098a1cb4a71992f24f7bfb424f6670db8313c9a855c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253545382e312d626c7565)](https://camo.githubusercontent.com/d6aac44f81cb2e6f4e71f098a1cb4a71992f24f7bfb424f6670db8313c9a855c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253545382e312d626c7565)[![CodeIgniter](https://camo.githubusercontent.com/ce252dce29520219a29abfe1c6b920c78f73e0f142b37233dbf19776c3d0aab7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f646549676e697465722d253545342e352d626c7565)](https://camo.githubusercontent.com/ce252dce29520219a29abfe1c6b920c78f73e0f142b37233dbf19776c3d0aab7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f646549676e697465722d253545342e352d626c7565)[![GitHub license](https://camo.githubusercontent.com/947a7c680ad4e7880d2f2ef96fd2bbda2a5f24aefe03911371bf2324f5071a60/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f64677669727475616c2f636f646569676e69746572342d6d6574612d696e666f)](https://github.com/dgvirtual/codeigniter4-meta-info/blob/develop/LICENSE)[![contributions welcome](https://camo.githubusercontent.com/9e93e892d0685e1bf7a1d0bd7c8410d6ecf2086a0a7b48dd58a6b96fa556ea2a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f6e747269627574696f6e732d77656c636f6d652d627269676874677265656e2e7376673f7374796c653d666c6174)](https://github.com/dgvirtual/codeigniter4-meta-info/pulls)

Usage case
----------

[](#usage-case)

Lets say you have a `users` table to store data of users. Suppose you need to add aditional fields to the user table to store additional information, whether this is a bio, a website URL, social links, or anything else.

You can either change the main table each time you need such changes, or, alternatively, – store such data in a separate table, without constantly changing the database schema.

Using this library you can add additional information to a user. Moreover, such data can be seamlessly integrated into the Create/Edit User form so you do not have to modify that one manually on each change of user data schema.

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

[](#installation)

Install via Composer (you will have to set minimum stability to dev, as this is pre-release library):

```
composer config minimum-stability dev
composer require dgvirtual/codeigniter4-meta-info

```

Then run the migration to setup the database table meta\_info (assuming you already configured your database):

```
php spark migrate -n \Dgvirtual\MetaInfo

```

Setup 1. Defining Meta Fields
-----------------------------

[](#setup-1-defining-meta-fields)

If you want to get a functionality preview, you can enable the demo code (read the section [demo](#demo) below).

First you create a config class for your users table, `app/Config/Users.php`. Put a property `$metaFields` into that class:

```
public $metaFields = [
    'Social Links' => [
        'blog' => [
            'label' => 'Blog',
            'type'  => 'text',
            'validation' => 'permit_empty|valid_url_strict'
        ],
    ],
];
```

In the above example:

- `Social links` is a subcategory that can later be used to build a categorized view for the data;
- the key `type` corresponds to the field type (text, checkbox, etc.) in the view (Supported `type`values: checkbox, textarea, text, and other "text" variants: number, password, email, tel, url, date, time, week, month, color).
- `blog` is the `column` for our data.

The other fields are used for data validation:

- `label` will act as label for validation rule and a label for HTML input, and
- `validation` key =&gt; value pair will be transformed into a `rules` with validation rules as value.

Setup 2. Adding Trait to your Entity class
------------------------------------------

[](#setup-2-adding-trait-to-your-entity-class)

Add the `HasMeta` trait and a protected `$configClass` property with a string value, the name of the above-mentioned Config class containing `$metaFields` array, to the Entity class that represents your resource.

```
use Dgvirtual\MetaInfo\Traits\HasMeta;
use CodeIgniter\Entity;

class User extends Entity
{
    use HasMeta;

    protected string $configClass = 'Users';
}
```

Manipulating data
-----------------

[](#manipulating-data)

The User entity has a trait applied, `HasMeta`, that provides all the functionality you should need to work with the meta information for that user.

### meta(string $key)

[](#metastring-key)

This returns the value of the user's meta named `$key`, or `null` if nothing has been set for that user. The name is the key of the array mentioned above.

```
$blog = $user->meta('blog');
```

### allMeta()

[](#allmeta)

This returns all meta fields for this user. Note that it returns the full database results, not just the name/value.

```
$meta = $user->allMeta();

var_dump($meta);

// Returns:
[
    'resource_id' => 123,
    'class' => 'App\Entities\User',
    'key' => 'blog',
    'value' => 'http://example.com',
    'created_at' => '2025-01-12 12:31:12',
    'updated_at' => '2025-01-12 12:31:12',
]
```

### hasMeta(string $key)

[](#hasmetastring-key)

Used to check if a user has a value set for the given meta field.

```
if ($user->hasMeta('foo')) {
    //
}
```

### saveMeta(string $key, $value)

[](#savemetastring-key-value)

Saves a single meta value to the user. This is immediately saved. There is no need to save the User through the UserModel.

```
$url = $this->request->getPost('blog');
$user->saveMeta('blog', $url);
```

### deleteMeta(string $key)

[](#deletemetastring-key)

Deletes a single meta value from the user. This is immediately deleted. There is no need to save the User through the UserModel.

```
$user->deleteMeta('blog');
```

### deleteResourceMeta()

[](#deleteresourcemeta)

Deletes all meta info associated with an entity. To be used when purging a record.

```
$user->deletResouceMeta();
```

### syncMeta(array $post)

[](#syncmetaarray-post)

Given an array of key/value pairs representing the name of the meta field and it's value, this will update existing meta values, insert new ones, and delete any ones that were not passed in. Useful when grabbing the information from a form and updating all the values at once.

```
$post = [
    'blog' => 'http://example.com',
    'fb' => 'johnny.rose'
];
$user->syncMeta($post);
```

`syncMeta()` will also delete meta data for the resource that is present in `meta_info` but not present in the corresponding config file's `$metaFields` property, and therefore not used (usually happens if you change `$metaFields` at some point, thus orphaning some data).

### metaValidationRules(string $prefix=null)

[](#metavalidationrulesstring-prefixnull)

This examines the specified config file and returns an array with the names of each field and their validation rules, ready to be used within CodeIgniter's validation library. If your form groups the name as an array, (like `meta[blog]`) you may specify the prefix to append to the field names so that validation will pick it up properly.

```
$rules = $user->metaValidationRules('meta');

var_dump($rules);

// Returns:
[
    'meta.blog' => 'required|string|valid_url',
]
```

### Using views for meta info display/editing

[](#using-views-for-meta-info-displayediting)

You can use directly (or copy and adapt) views in `src/Views/` to include the meta info in your CRUD views as, for example, view cells, for display (`meta_display`) or editing (`meta_edit`). See how that is done in the [Demo](#demo) code.

Using the library for searches
------------------------------

[](#using-the-library-for-searches)

You will want to get the data from meta\_info table the same way you would from a related table, and, for example, display it in search results.

Of course that is not as simple as when using a simple join.

To do that you will need to employ `WithMeta` trait in your model:

```
namespace App\Models;

use App\Entities\User;
use CodeIgniter\Model;
use Dgvirtual\MetaInfo\Traits\WithMeta;

class UserModel extends Model
{
    use WithMeta;
    // other code
}
```

Now you can use the methods provided by WithMeta to build queries. For example, you can write the `search()` method in your model employing the trait methods `generateMetaSelectClause`, `joinMetaInfo` and `orLikeInMetaInfo()` when constructing the query; for example:

```
public function search(string $term, int $limit = 100, int $offset = 0): array
{
    $termInMeta = config(\Config\Users::class)->includeMetaFieldsInSearch;

    // First: get the expanded select clause that includes info from meta_info table
    $selectClause = $this->generateMetaSelectClause($termInMeta, \App\Entities\User::class);

    $query = $this->select($selectClause)->distinct();

    if (!empty($termInMeta)) {
        // Second: generate the join statement
        // here the User::class is string representation of the entity class
        $query->joinMetaInfo(\App\Entities\User::class, $this->table);
    }

    if ($term) {
        $query->like('first_name', $term, 'right', true, true)
                ->orLike('last_name', $term, 'right', true, true)
                ->orLike('username', $term, 'right', true, true);

        if (!empty($termInMeta)) {
            foreach ($termInMeta as $metaField) {
                // Third: perform the search through like statements
                $query->orLikeInMetaInfo($metaField, $term, 'both', true, true);
            }
        }
    }

    return $query->findAll($limit, $offset);
}
```

This method can now be used in controllers to perform searches and get information with data from meta\_info table neatly integrated into the data from the main table.

Demo
----

[](#demo)

A demo is provided with this library. Enabling demo would create a table `testusers` in your DB, which you can remove later.

Steps to enable the demo:

1. update Config\\Autoload class to include demo namespace into the list of available namespaces:

    ```
    public $psr4 = [
        APP_NAMESPACE    => APPPATH,
        // add two lines temporarily:
        'Dgvirtual\Demo' => ROOTPATH . 'vendor/dgvirtual/codeigniter4-meta-info/demo',
        'Tests\Support'  => ROOTPATH . 'vendor/dgvirtual/codeigniter4-meta-info/tests/_support',
    ];
    ```
2. Setup the database if you have not done so already, then migrate and seed the demo table:

    ```
    php spark migrate -n \Dgvirtual\MetaInfo
    php spark migrate -n \Dgvirtual\Demo
    php spark db:seed \Tests\Support\Database\Seeds\TestusersSeeder

    ```
3. Copy the routes you will need into your Config\\Routes.php file:

    ```
    $routes->group('testusers', ['namespace' => 'Dgvirtual\Demo\Controllers'], static function ($routes) {
        $routes->get('', 'TestusersController::index');
        $routes->get('create', 'TestusersController::create');
        $routes->get('edit/(:num)', 'TestusersController::edit/$1');
        $routes->get('display/(:num)', 'TestusersController::display/$1');
        $routes->post('save', 'TestusersController::save');
        $routes->post('save/(:num)', 'TestusersController::save/$1');
        $routes->post('delete/(:num)', 'TestusersController::delete/$1');
    });
    $routes->get('meta_info', '\Dgvirtual\Demo\Controllers\MetaInfoController::index');
    ```

    Now you can run `php spark serve` and open the demo at
4. To modify the meta fields assigned to the `testuser` you can copy the demo's file `Config/Testusers.php` to `app/Config`, change it's namespace to `Config` and modify it to your liking; the changes will be reflected in the demo's `create` and `edit` pages. The display page does not use a dynamic template, so it will remain the same.

**To disable the demo**, please undo the above-mentioned changes in files. To remove the demo table, use Codeigniter4 [migration rollback functionality](https://codeigniter4.github.io/userguide/dbmgmt/migration.html#migrate-rollback).

Contributing
------------

[](#contributing)

If you would like to contribute to this project, please fork the repository and submit a pull request.

Credits
-------

[](#credits)

This library was created by Donatas Glodenis. You can reach out to me at \[\] for any questions or feedback.

The library started as an adaptation of Bonfire2 Users meta info functionality for general CodeIgniter 4 use. Bonfire2 was created by Lonnie Ezell  and contributors. For more information, visit the [Bonfire2 project](https://github.com/lonnieezell/Bonfire2).

License
-------

[](#license)

This project is licensed under the MIT License. See the LICENSE file for details.

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/c37acd333f5bf437ef9506328912e279f64fd3b87959b023a73ada7a8fdede4e?d=identicon)[dgvirtual](/maintainers/dgvirtual)

---

Top Contributors

[![dgvirtual](https://avatars.githubusercontent.com/u/2669306?v=4)](https://github.com/dgvirtual "dgvirtual (27 commits)")

### Embed Badge

![Health badge](/badges/dgvirtual-codeigniter4-meta-info/health.svg)

```
[![Health](https://phpackages.com/badges/dgvirtual-codeigniter4-meta-info/health.svg)](https://phpackages.com/packages/dgvirtual-codeigniter4-meta-info)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90440.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

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