PHPackages                             tatter/alerts - 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. tatter/alerts

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

tatter/alerts
=============

Lightweight user alerts for CodeIgniter 4

v3.1.0(3y ago)4072.4k↓24.8%10[1 PRs](https://github.com/tattersoftware/codeigniter4-alerts/pulls)6MITPHPPHP ^7.4 || ^8.0

Since Mar 18Pushed 2y ago8 watchersCompare

[ Source](https://github.com/tattersoftware/codeigniter4-alerts)[ Packagist](https://packagist.org/packages/tatter/alerts)[ Docs](https://github.com/tattersoftware/codeigniter4-alerts)[ Fund](https://paypal.me/tatter)[ GitHub Sponsors](https://github.com/tattersoftware)[ RSS](/packages/tatter-alerts/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (15)Used By (6)

Tatter\\Alerts
==============

[](#tatteralerts)

Lightweight user alerts for CodeIgniter 4

[![](https://github.com/tattersoftware/codeigniter4-alerts/workflows/PHPUnit/badge.svg)](https://github.com/tattersoftware/codeigniter4-alerts/actions/workflows/test.yml)[![](https://github.com/tattersoftware/codeigniter4-alerts/workflows/PHPStan/badge.svg)](https://github.com/tattersoftware/codeigniter4-alerts/actions/workflows/analyze.yml)[![](https://github.com/tattersoftware/codeigniter4-alerts/workflows/Deptrac/badge.svg)](https://github.com/tattersoftware/codeigniter4-alerts/actions/workflows/inspect.yml)[![Coverage Status](https://camo.githubusercontent.com/93cd120d284ad78ae7bae6b443e586476783910c34e210129b11f1d018520285/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f746174746572736f6674776172652f636f646569676e69746572342d616c657274732f62616467652e7376673f6272616e63683d646576656c6f70)](https://coveralls.io/github/tattersoftware/codeigniter4-alerts?branch=develop)

[![Screenshot](https://github.com/tattersoftware/codeigniter4-alerts/raw/master/img/screenshot2.png)](https://github.com/tattersoftware/codeigniter4-alerts/blob/master/img/screenshot2.png)

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

[](#quick-start)

1. Install with Composer: `> composer require tatter/alerts`
2. Enable the `alerts` filter in **app/Config/Filters.php**
3. Add the `{alerts}` token to your View Layouts
4. Load the helper: `helper('alerts');`
5. Set an alert with a class and message: `alert('success', 'You did it!')`

Features
--------

[](#features)

Provides integrated user alerts for CodeIgniter 4 with a variety of built-in templates and custom template support.

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

[](#installation)

Install easily via Composer to take advantage of CodeIgniter 4's autoloading capabilities and always be up-to-date:

```
composer require tatter/alerts
```

Or, install manually by downloading the source files and adding the directory to `app/Config/Autoload.php`.

> Note: The default display template expects [Bootstrap](https://getbootstrap.com) (not included)

Configuration (optional)
------------------------

[](#configuration-optional)

The library's default behavior can be changed using its config file. Copy **examples/Alerts.php** to **app/Config/Alerts.php** and follow the instructions in the comments. If no config file is found the library will use its defaults.

The Config file consists of two properties.

### Templates

[](#templates)

The `$template` property sets the path to the View file which will be used to format your alerts. The default template has HTML tags and classes designed for use with [Bootstrap 5 Alerts](https://getbootstrap.com/docs/5.2/components/alerts/), but the library includes additional templates for you to choose:

- `Tatter\Alerts\Views\Bootstrap4`: Compatible with the Bootstrap 4 CSS Framework
- `Tatter\Alerts\Views\Foundation`: Compatible with the Foundation CSS Framework
- `Tatter\Alerts\Views\Vanilla`: A framework-free implementation, with classes available for your own CSS styling

And of course you can add your own. The view file will be passed an array of tuples named `$alerts`, with each tuple in the format `[string $class, string $content]`. Your view file should unpack each tuple:

```
foreach ($alerts as $alert) {
    [$class, $content] = $alert;
```

... then output the alert `$content` wrapped in some appropriate HTML tags with whatever styling or classes you like based on `$class`.

> Note: This library *does not include* assets for Bootstrap or Foundation. Check out [Tatter\\Frontend](https://github.com/tattersoftware/codeigniter4-frontend) for an integrated solution.

### Classes

[](#classes)

The `$classes` property is a mapping of Session keys to their CSS classes. This lets you control which Session keys are deemed "alerts" and how to designate them to your view template. The default list is a generous guess at common keys used by the framework and modules, with the addition of the Bootstrap alert classes, but in most cases you will want to slim this down or replace it altogether with your own.

*See **Warnings** below for some caveats to consider when auto-populating Session keys into displayable content.*

Filter
------

[](#filter)

In order to use the `AlertsFilter` you must add apply it to your target routes. The filter only applies when the token is present so it is safe to apply it globally in **app/Config/Filters.php**. See [Controller Filters](https://codeigniter.com/user_guide/incoming/filters.html) for more info.

> Note: The alias is predefined for you as "alerts", and only the `after()` method is relevant.

Token
-----

[](#token)

The token is the following string: `{alerts}`. Place this in your View layout where you want the alerts to appear. For example:

```

    {alerts}

    ...
```

Usage
-----

[](#usage)

If installed correctly CodeIgniter 4 will detect and autoload the library, filter, helper, and config. The filter will gather any alerts from the Session keys defined in your Config, pass them through your View template for formatting, and place them into your Response body wherever you have placed your token - you just need to set the alerts!

Alerts can be set directly in the Session, ideally as flashdata (so they are not repeated):

```
session()->setFlashdata('success', 'Your account has been updated.');
```

Many times your alerts will be handled during redirect, so you can take advantage of the framework's `RedirectResponse` class method `with()` to apply the flashdata directly:

```
if (! $fruit = $this->getPost('fruit')) {
    return redirect()->back()->with('error', 'You must select a fruit!');
}
```

### Helper

[](#helper)

This library also includes a helper function, which has the added benefit of merging values and checking for collision. Initialize the helper to us the convenience wrapper function:

```
helper(['alerts']);
alert('error', 'You must accept the terms of service to continue.');
```

The helper adds a few features (like collision detection and alert merging) but may throw exceptions in some circumstances - read the **Collision** section below.

### Collector

[](#collector)

There is a [Toolbar Collector](https://www.codeigniter.com/user_guide/testing/debugging.html#creating-custom-collectors)bundled with this library to ease development and integration. It is enabled by default and should appear in the development environment whenever the Toolbar is active.

Warnings
--------

[](#warnings)

The premise of this library is to take data from `$_SESSION` and display it to visitors of your site. There are a few precautions mentioned here, but in general: use strong security practices and good sense any time you are moving data between the backend and public views.

### Security

[](#security)

Ideally `$_SESSION` should not contain critical information like passwords or credit card numbers. You should also not use distinguishable identifiers as Session keys, and this goes for `Alerts` as well. Keep the keys you use basic, and consider pairing down the Config file's to only those values your app and modules need.

For example, say you add a payment library to your project and some developer was using the following code to test credit card submission and forgot to remove it:

```
$_SESSION['debug'] = (string) $user->getCreditCard();
```

Since "debug" is a valid `Alerts` key this credit card number will now become a alert displayed visually on the user's browser window!

### Collision

[](#collision)

Another concern is Session collision. Starting with an example this time:

```
/** @var Notice $notice */
$notice = model(NoticeModel::class)->first();
session('notice', $notice);
...

// Later that same day...
alert('notice', 'Site statistics are currently being updated, expect longer load times.');
```

We have just tried to set an alert for a Session key that already exists and contains something that is not another alert! There are a few ways that this can play out, but ultimately this was a mistake and you should take care to avoid it.

To clarify the example:

1. `AlertsFilter` will quietly ignore Session data that is not a string or an array of strings, so there is no problem with `session('notice', $notice);`.
2. Using the Alerts Helper to set your alert includes the additional layer of collision protection, but will cause the `alert()` function to throw an exception.
3. Setting Session keys yourself is a fine solution, but you must handle checks for existing keys or risk overwriting data.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity44

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 98.4% 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 ~121 days

Recently: every ~162 days

Total

12

Last Release

1285d ago

Major Versions

v1.1.0 → v2.0.02019-03-25

v2.1.1 → v3.0.0-rc.12022-01-02

PHP version history (3 changes)v1.0.0PHP ^7.0

v2.1.0PHP ^7.3 || ^8.0

v3.0.0PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ebe908b4fe73807ecdd9f88733342199c9991b7de800329f5b2b787c8210d62?d=identicon)[MGatner](/maintainers/MGatner)

---

Top Contributors

[![MGatner](https://avatars.githubusercontent.com/u/17572847?v=4)](https://github.com/MGatner "MGatner (61 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

codeigniteralertsmessagescodeigniter4dialogs

### Embed Badge

![Health badge](/badges/tatter-alerts/health.svg)

```
[![Health](https://phpackages.com/badges/tatter-alerts/health.svg)](https://phpackages.com/packages/tatter-alerts)
```

###  Alternatives

[prologue/alerts

Prologue Alerts is a package that handles global site messages.

3486.1M30](/packages/prologue-alerts)[codeigniter4/settings

Settings library for CodeIgniter 4

93499.3k24](/packages/codeigniter4-settings)[codeigniter4/devkit

Development toolkit for CodeIgniter libraries and projects

68187.1k82](/packages/codeigniter4-devkit)[tatter/patches

Automated project updates for CodeIgniter 4

3588.4k3](/packages/tatter-patches)[michalsn/codeigniter4-uuid

UUID and ULID package for CodeIgniter 4 with support for Model.

4728.7k4](/packages/michalsn-codeigniter4-uuid)[cartalyst/alerts

Alerts allows you to easily pass alert messages to your Laravel views.

3064.2k](/packages/cartalyst-alerts)

PHPackages © 2026

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