PHPackages                             ngekoding/codeigniter-api-query-parser - 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. [API Development](/categories/api)
4. /
5. ngekoding/codeigniter-api-query-parser

ActiveLibrary[API Development](/categories/api)

ngekoding/codeigniter-api-query-parser
======================================

A query parser for REST-APIs based on CodeIgniter

v1.0.2(2y ago)5191[1 issues](https://github.com/ngekoding/codeigniter-api-query-parser/issues)MITPHPPHP &gt;=5.6

Since Oct 30Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ngekoding/codeigniter-api-query-parser)[ Packagist](https://packagist.org/packages/ngekoding/codeigniter-api-query-parser)[ RSS](/packages/ngekoding-codeigniter-api-query-parser/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

CodeIgniter API Query Parser
============================

[](#codeigniter-api-query-parser)

Simple request query parameter parser for REST-APIs based on CodeIgniter framework. Works for both CodeIgniter 3 and CodeIgniter 4.

Inspired by [Lumen API Query Parser](https://github.com/ngabor84/lumen-api-query-parser)

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

[](#requirements)

- PHP 5.6 or above
- CodeIgniter 3 or CodeIgniter 4
- PHPSQLParser ^4.5

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

[](#installation)

You just need to use composer and everything is done.

```
composer require ngekoding/codeigniter-api-query-parser
```

Usage
-----

[](#usage)

Here is the example for CodeIgniter 3 and CodeIgniter 4. Actually there is no different by the use of the library, just different how to create the query builder.

### CodeIgniter 3 Example

[](#codeigniter-3-example)

```
// CodeIgniter 3 Example

// Get a query builder
// Please note: we don't need to call ->get() here
$queryBuilder = $this->db->select('p.*, c.name category')
                    ->from('posts p')
                    ->join('categories c', 'c.id=p.category_id');

/**
 * The first parameter is the query builder instance
 * and the second is the codeigniter version (3 or 4)
 */
$queryParser = new \Ngekoding\CodeIgniterApiQueryParser\QueryParser($queryBuilder);
$result = $queryParser->applyParams(); // done

print_r($result);
```

The above example will output an array with `data` and `pagination`:

```
Array
(
    [data] => Array
        (
            [0] => ...
            [1] => ...
        )
    [pagination] => Array
        (
            [current_page] => int
            [per_page] => int
            [from] => int
            [to] => int
            [total] => int
            [last_page] => int
            [links] => Array
                (
                    [first] => string
                    [prev] => string or null
                    [next] => string or null
                    [last] => string
                )
        )
)

```

### CodeIgniter 4 Example

[](#codeigniter-4-example)

The different only by the way to create the Query Builder.

```
// CodeIgniter 4 Example

$db = db_connect();
$queryBuilder = $db->from('posts p')
                   ->select('p.*, c.name category')
                   ->join('categories c', 'c.id=p.category_id');

$queryParser = new \Ngekoding\CodeIgniterApiQueryParser\QueryParser($queryBuilder);
$result = $queryParser->applyParams(); // done

print_r($result);
```

Query Syntax
------------

[](#query-syntax)

### Filtering

[](#filtering)

Q: /users?filter\[\]=name:ct:admin
R: will return the array of the users whose names contains the `admin` string

**Available filter options**

OperatorDescriptionExamplectString containsname:ct:PeternctString NOT containsname:nct:PeterswString starts withusername:sw:adminewString ends withemail:ew:gmail.comeqEqualslevel:eq:3neNot equalslevel:ne:4gtGreater thanlevel:gt:2geGreater than or equallevel:ge:3ltLess thanlevel:lt:4leLess than or equallevel:le:3inIn arraylevel:in:1,2,3### Sorting

[](#sorting)

Q: /users?sort\[\]=name:ASC
R: will return the array of the users sort by their `names` ascending

### Pagination

[](#pagination)

Q: /users?limit=10&amp;page=3
R: will return a part of the array of the users (from the 21st to 30th)

Column Alias
------------

[](#column-alias)

When working with SQL expression in selecting data or using join with ambiguous column name, **the library automatically will try to find the original column name or its expression** to use for the filter feature. But, you can still manually define the column alias for better use, expecially to resolving the ambiguous column name when using join.

For example, joining posts table with categories table in the example above will return an `id` from the posts table. So, when we try to get the data with `id` 1, 2 or 3 (`SQL WHERE IN`) using filter\[\]=id:in:1,2,3 we get the ambiguous column error.

Here is the **column alias** to solve it.

```
$queryParser = new \Ngekoding\CodeIgniterApiQueryParser\QueryParser($queryBuilder);

// Tell that the `id` is `p.id` (posts table id)
$queryParser->addColumnAlias('id', 'p.id');

// Or add multiple aliases at once
$queryParser->addColumnAlias([
    'id' => 'p.id',
    'title' => 'p.title'
]);

$result = $queryParser->applyParams(); // done
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~113 days

Total

3

Last Release

1070d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

codeigniter-librarycodeigniter-query-parserrest-api

### Embed Badge

![Health badge](/badges/ngekoding-codeigniter-api-query-parser/health.svg)

```
[![Health](https://phpackages.com/badges/ngekoding-codeigniter-api-query-parser/health.svg)](https://phpackages.com/packages/ngekoding-codeigniter-api-query-parser)
```

###  Alternatives

[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[showdoc/showdoc

ShowDoc is a tool greatly applicable for an IT team to share documents online

12.8k7.0k](/packages/showdoc-showdoc)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

74513.7M114](/packages/meilisearch-meilisearch-php)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)[hubspot/api-client

Hubspot API client

23914.2M16](/packages/hubspot-api-client)

PHPackages © 2026

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