PHPackages                             davodm/dgcontent-ci - 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. [Caching](/categories/caching)
4. /
5. davodm/dgcontent-ci

ActiveLibrary[Caching](/categories/caching)

davodm/dgcontent-ci
===================

A simple CodeIgniter 4 package to interact with DGTTeam Content API

v0.1.5(1y ago)024MITPHPPHP ^7.4 || ^8.0

Since Oct 8Pushed 1y ago1 watchersCompare

[ Source](https://github.com/davodm/dgcontent-ci)[ Packagist](https://packagist.org/packages/davodm/dgcontent-ci)[ RSS](/packages/davodm-dgcontent-ci/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (19)Used By (0)

DG Content for Codeigniter 4
============================

[](#dg-content-for-codeigniter-4)

[![Latest Stable Version](https://camo.githubusercontent.com/36d1837da1f40ef21f0f511451736f7dba60c8922c0b89c6aa1d9ceb5d8f78f2/68747470733a2f2f706f7365722e707567782e6f72672f6461766f646d2f64672d636f6e74656e742d63692f76)](//packagist.org/packages/davodm/dg-content-ci)[![Total Downloads](https://camo.githubusercontent.com/ade5fcc1404662c8f769b4b906dfc95a2aea270fc8e128ed871b0ea40efa7c6d/68747470733a2f2f706f7365722e707567782e6f72672f6461766f646d2f64672d636f6e74656e742d63692f646f776e6c6f616473)](//packagist.org/packages/davodm/dg-content-ci)[![Latest Unstable Version](https://camo.githubusercontent.com/37ed1cb5ff107fadb0e57bf7f2de6c78d0d4f3a430e0d8d6fd1e62e4d154c71f/68747470733a2f2f706f7365722e707567782e6f72672f6461766f646d2f64672d636f6e74656e742d63692f762f756e737461626c65)](//packagist.org/packages/davodm/dg-content-ci)[![License](https://camo.githubusercontent.com/38de5d2a8bdbc36385dabc67805a18796e961c73007f7c121fc716366aa16e11/68747470733a2f2f706f7365722e707567782e6f72672f6461766f646d2f64672d636f6e74656e742d63692f6c6963656e7365)](//packagist.org/packages/davodm/dg-content-ci)

A robust **CodeIgniter 4** package to interact with the **DGTTeam Content API**, featuring caching mechanisms, secure API key management via environment variables.

Features
--------

[](#features)

- **Seamless API Integration:** Interact with the DGTTeam Content API effortlessly.
- **Caching Mechanism:** Reduce API calls and improve performance with customizable caching.
- **Secure Configuration:** Manage API keys and sensitive data using environment variables.
- **Flexible Usage:** Easily fetch posts, single posts, categories, and update post statistics.
- **Error Handling:** Gracefully handle API errors with meaningful messages and logging.
- **Extensible:** Easily extend the package to include additional API endpoints or features.

Prerequisites
-------------

[](#prerequisites)

Before integrating **DGContent** into your project, ensure you have the following:

- **PHP &gt;= 7.4**
- **Composer** installed globally.
- **CodeIgniter 4** project set up.
- Familiarity with **OOP PHP** and **CodeIgniter 4**.

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

[](#installation)

You can install the package via Composer. Run the following command in your CodeIgniter 4 project directory:

```
composer require davodm/dgcontent-ci
```

Configuration
-------------

[](#configuration)

1. Environment Variables Store sensitive information like the API key in your .env file to keep it secure and out of version control.

Add the following entries to your .env file:

```
# API Key for DGTTeam Content API
DGCONTENT_API_KEY=your_api_key_here
# Cache duration in seconds (default: 3600)
DGCONTENT_CACHE_TTL=3600
# Website Domain (without http/https)
DGCONTENT_WEBSITE=xxx.com
# Optional: Base URL for the DGTTeam Content API
DGCONTENT_API_BASE_URL=https://xxx.com/api/
# Optional: Request timeout in seconds (default: 10)
DGCONTENT_TIMEOUT=10
```

2. Configuration File The package comes with a configuration file located at `src/Config/DGContentCI.php`. You can customize default settings by modifying this file if necessary.

Usage
-----

[](#usage)

You can initialize the library directly in your controller.

```
$dgContent = new \DGContent\Libraries\Content();
$params = [
    'limit' => 5,
    'offset' => 0,
    'category' => 'Technology',
    'tags' => 'JavaScript,Node.js'
];

$posts = $dgContent
    ->setCacheDuration(7200)
    ->getPosts($params);

if ($posts['posts']) {
    foreach ($posts['posts'] as $post) {
        echo esc($post['title']) . '';
    }
} else {
    echo "No posts found.";
}
```

Functions
---------

[](#functions)

The package provides the following functions to interact with the DGTTeam Content API:

### `getPosts($params)`

[](#getpostsparams)

Fetch posts based on the specified parameters and return `total` (as total number for pagination) and `posts` array.

**Parameters:**

- `limit`: Number of posts to fetch (default: 10).
- `offset`: Offset for pagination (default: 0).
- `category`: Filter posts by category slug. could be an array or string with comma separated values. (optional)
- `tags`: Filter posts by tags. could be an array or string with comma separated values. (optional)
- `language`: Filter posts by language code e.g. fa, en, es, fr. (optional)

**Returns:** An array with `total` (total number of posts) and `posts` array containing post objects.

### `getPost($params)`

[](#getpostparams)

Fetch a single post by ID or slug and return the post object.

**Parameters:**

- `id`: Post ID. (one of `id` or `slug` is required)
- `slug`: Post slug.

**Returns:** A single post object.

### `getPage($slug)`

[](#getpageslug)

Fetch a single page by slug and return the page object.

**Returns:** A single page object.

### `getCategories(bool $websiteOnly = false)`

[](#getcategoriesbool-websiteonly--false)

Fetch all available categories. If `$websiteOnly` is set to `true`, it will only return categories that are attached to the website specified in the environment variables.

**Returns:** An array of category objects.

### `updateStats(string $type, string $id, int $count=1)`

[](#updatestatsstring-type-string-id-int-count1)

Update post statistics (views, likes, dislikes).

**Parameters:**

- `type`: Type of statistic to update (views, likes, dislikes).
- `id`: Post ID.
- `count`: Number of counts to add (default: 1).

**Returns:** `true` if the statistics are updated successfully, `false` otherwise.

### `setCacheDuration(int $duration)`

[](#setcachedurationint-duration)

Set the cache duration for API responses in seconds.

### `setProcessResult(bool $processResult)`

[](#setprocessresultbool-processresult)

Set whether to process the API response before returning it. Default is `true`.

### `clearCache()`

[](#clearcache)

Clear the cache for the API responses.

#### Post Object

[](#post-object)

The post object returned by the `getPosts` and `getPost` functions contains the following properties, which may vary based on the API response:

```
[
    'id' => "xxx",
    'title' => 'Post Title',
    'slug' => 'post-title',
    'featuredImage' => 'https://example.com/image.jpg',
    'images' => [ // Images in the content
        'https://example.com/image1.jpg',
        'https://example.com/image2.jpg'
        ],
    'content' => 'Post content',
    'category' => [
        'title' => 'Category Title',
        'slug' => 'category-slug'
    ],
    'tags' => ['Tag 1', 'Tag 2'],
    'site' => [ // Based on processed result
        'title' => 'Site Title',
        'slug' => 'site-slug',
        'url' => 'xxx.com',
    ],
    'stats'=> [
        'views' => 100,
        'likes' => 10,
        'dislikes' => 2
    ],
    'language' => 'en', // Could be null or not present
    'source' => 'https://example.com', // Could be null or not present
    'author' => 'Author Name', // Could be null or not present
    'createdAt' => \CodeIgniter\I18n\Time Object, // Based on processed result
    'updatedAt' => '2024-10-14T22:26:23Z', // If it's not processed
]
```

Error Handling
--------------

[](#error-handling)

The package gracefully handles API errors and logs them for debugging purposes. If an error occurs during API requests, the package will throw an exception with a meaningful error message and you can catch it in your application to log or display the error.

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.

Author
------

[](#author)

Davod Mozafari - [Twitter](https://twitter.com/davodmozafari)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance42

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

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 ~5 days

Recently: every ~17 days

Total

17

Last Release

502d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b30abdf7be032daaa2618d8a968b66a54156db753b2abfc027c6b1e72280216?d=identicon)[davodm](/maintainers/davodm)

---

Top Contributors

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

---

Tags

phpcachingapi clientcodeigniter4content-apidg-content-ci

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/davodm-dgcontent-ci/health.svg)

```
[![Health](https://phpackages.com/badges/davodm-dgcontent-ci/health.svg)](https://phpackages.com/packages/davodm-dgcontent-ci)
```

###  Alternatives

[voku/simple-cache

Simple Cache library

322.5M7](/packages/voku-simple-cache)[alekseykorzun/memcached-wrapper-php

Optimized PHP 5 wrapper for Memcached extension that supports dog-piling, igbinary and local storage

2984.6k1](/packages/alekseykorzun-memcached-wrapper-php)[rapidwebltd/rw-file-cache

RW File Cache is a PHP File-based Caching Library. Its syntax is designed to closely resemble the PHP memcache extension.

15191.3k7](/packages/rapidwebltd-rw-file-cache)

PHPackages © 2026

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