{"id":13818257,"url":"https://github.com/tattersoftware/codeigniter4-alerts","last_synced_at":"2025-08-19T06:38:23.218Z","repository":{"id":34302343,"uuid":"176344553","full_name":"tattersoftware/codeigniter4-alerts","owner":"tattersoftware","description":"Lightweight user alerts for CodeIgniter 4","archived":false,"fork":false,"pushed_at":"2024-01-18T14:47:06.000Z","size":204,"stargazers_count":40,"open_issues_count":1,"forks_count":9,"subscribers_count":8,"default_branch":"develop","last_synced_at":"2025-08-10T16:43:11.314Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tattersoftware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-18T18:16:09.000Z","updated_at":"2025-05-25T12:51:48.000Z","dependencies_parsed_at":"2024-01-05T12:42:33.828Z","dependency_job_id":"2fab23d8-1db7-4a0e-b3d2-8de91744fde7","html_url":"https://github.com/tattersoftware/codeigniter4-alerts","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/tattersoftware/codeigniter4-alerts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattersoftware%2Fcodeigniter4-alerts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattersoftware%2Fcodeigniter4-alerts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattersoftware%2Fcodeigniter4-alerts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattersoftware%2Fcodeigniter4-alerts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tattersoftware","download_url":"https://codeload.github.com/tattersoftware/codeigniter4-alerts/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattersoftware%2Fcodeigniter4-alerts/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271113829,"owners_count":24701614,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-19T02:00:09.176Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T07:00:37.683Z","updated_at":"2025-08-19T06:38:23.194Z","avatar_url":"https://github.com/tattersoftware.png","language":"PHP","funding_links":[],"categories":["libraries"],"sub_categories":[],"readme":"# Tatter\\Alerts\nLightweight user alerts for CodeIgniter 4\n\n[![](https://github.com/tattersoftware/codeigniter4-alerts/workflows/PHPUnit/badge.svg)](https://github.com/tattersoftware/codeigniter4-alerts/actions/workflows/test.yml)\n[![](https://github.com/tattersoftware/codeigniter4-alerts/workflows/PHPStan/badge.svg)](https://github.com/tattersoftware/codeigniter4-alerts/actions/workflows/analyze.yml)\n[![](https://github.com/tattersoftware/codeigniter4-alerts/workflows/Deptrac/badge.svg)](https://github.com/tattersoftware/codeigniter4-alerts/actions/workflows/inspect.yml)\n[![Coverage Status](https://coveralls.io/repos/github/tattersoftware/codeigniter4-alerts/badge.svg?branch=develop)](https://coveralls.io/github/tattersoftware/codeigniter4-alerts?branch=develop)\n\n![Screenshot](https://github.com/tattersoftware/codeigniter4-alerts/blob/master/img/screenshot2.png)\n\n## Quick Start\n\n1. Install with Composer: `\u003e composer require tatter/alerts`\n2. Enable the `alerts` filter in **app/Config/Filters.php**\n3. Add the `{alerts}` token to your View Layouts\n4. Load the helper: `helper('alerts');`\n4. Set an alert with a class and message: `alert('success', 'You did it!')`\n\n## Features\n\nProvides integrated user alerts for CodeIgniter 4 with a variety of built-in templates\nand custom template support.\n\n## Installation\n\nInstall easily via Composer to take advantage of CodeIgniter 4's autoloading capabilities\nand always be up-to-date:\n```bash\ncomposer require tatter/alerts\n```\n\nOr, install manually by downloading the source files and adding the directory to\n`app/Config/Autoload.php`.\n\n\u003e Note: The default display template expects [Bootstrap](https://getbootstrap.com) (not included)\n\n## Configuration (optional)\n\nThe library's default behavior can be changed using its config file. Copy\n**examples/Alerts.php** to **app/Config/Alerts.php** and follow the instructions in the\ncomments. If no config file is found the library will use its defaults.\n\nThe Config file consists of two properties.\n\n### Templates\n\nThe `$template` property sets the path to the View file which will be used to format your\nalerts. The default template has HTML tags and classes designed for use with\n[Bootstrap 5 Alerts](https://getbootstrap.com/docs/5.2/components/alerts/), but the library\nincludes additional templates for you to choose:\n* `Tatter\\Alerts\\Views\\Bootstrap4`: Compatible with the Bootstrap 4 CSS Framework\n* `Tatter\\Alerts\\Views\\Foundation`: Compatible with the Foundation CSS Framework\n* `Tatter\\Alerts\\Views\\Vanilla`: A framework-free implementation, with classes available for your own CSS styling\n\nAnd of course you can add your own. The view file will be passed an array of tuples named\n`$alerts`, with each tuple in the format `[string $class, string $content]`. Your view file\nshould unpack each tuple:\n```php\nforeach ($alerts as $alert) {\n    [$class, $content] = $alert;\n```\n... then output the alert `$content` wrapped in some appropriate HTML tags with whatever\nstyling or classes you like based on `$class`.\n\n\u003e Note: This library *does not include* assets for Bootstrap or Foundation. Check out\n\u003e [Tatter\\Frontend](https://github.com/tattersoftware/codeigniter4-frontend) for an integrated solution.\n\n### Classes\n\nThe `$classes` property is a mapping of Session keys to their CSS classes. This lets you\ncontrol which Session keys are deemed \"alerts\" and how to designate them to your view\ntemplate. The default list is a generous guess at common keys used by the framework and\nmodules, with the addition of the Bootstrap alert classes, but in most cases you will want\nto slim this down or replace it altogether with your own.\n\n*See **Warnings** below for some caveats to consider when auto-populating Session keys into displayable content.*\n\n## Filter\n\nIn order to use the `AlertsFilter` you must add apply it to your target routes. The filter\nonly applies when the token is present so it is safe to apply it globally in **app/Config/Filters.php**.\nSee [Controller Filters](https://codeigniter.com/user_guide/incoming/filters.html) for more info.\n\n\u003e Note: The alias is predefined for you as \"alerts\", and only the `after()` method is relevant.\n\n## Token\n\nThe token is the following string: `{alerts}`. Place this in your View layout where you want\nthe alerts to appear. For example:\n```php\n\u003cbody\u003e\n    \u003caside\u003e\n    {alerts}\n    \u003c/aside\u003e\n    \u003cmain class=\"wrapper\"\u003e\n    ...\n```\n\n## Usage\n\nIf installed correctly CodeIgniter 4 will detect and autoload the library, filter, helper,\nand config. The filter will gather any alerts from the Session keys defined in your Config,\npass them through your View template for formatting, and place them into your Response body\nwherever you have placed your token - you just need to set the alerts!\n\nAlerts can be set directly in the Session, ideally as flashdata (so they are not repeated):\n```php\nsession()-\u003esetFlashdata('success', 'Your account has been updated.');\n```\n\nMany times your alerts will be handled during redirect, so you can take advantage of\nthe framework's `RedirectResponse` class method `with()` to apply the flashdata directly:\n```php\nif (! $fruit = $this-\u003egetPost('fruit')) {\n    return redirect()-\u003eback()-\u003ewith('error', 'You must select a fruit!');\n}\n```\n\n### Helper\n\nThis library also includes a helper function, which has the added benefit of merging values\nand checking for collision. Initialize the helper to us the convenience wrapper function:\n```php\nhelper(['alerts']);\nalert('error', 'You must accept the terms of service to continue.');\n```\n\nThe helper adds a few features (like collision detection and alert merging) but may throw\nexceptions in some circumstances - read the **Collision** section below.\n\n### Collector\n\nThere is a [Toolbar Collector](https://www.codeigniter.com/user_guide/testing/debugging.html#creating-custom-collectors)\nbundled with this library to ease development and integration. It is enabled by default and\nshould appear in the development environment whenever the Toolbar is active.\n\n## Warnings\n\nThe premise of this library is to take data from `$_SESSION` and display it to visitors of\nyour site. There are a few precautions mentioned here, but in general: use strong security\npractices and good sense any time you are moving data between the backend and public views.\n\n### Security\n\nIdeally `$_SESSION` should not contain critical information like passwords or credit card\nnumbers. You should also not use distinguishable identifiers as Session keys, and this goes\nfor `Alerts` as well. Keep the keys you use basic, and consider pairing down the Config\nfile's to only those values your app and modules need.\n\nFor example, say you add a payment library to your project and some developer was using\nthe following code to test credit card submission and forgot to remove it:\n```php\n$_SESSION['debug'] = (string) $user-\u003egetCreditCard();\n```\n\nSince \"debug\" is a valid `Alerts` key this credit card number will now become a alert\ndisplayed visually on the user's browser window! \n\n### Collision\n\nAnother concern is Session collision. Starting with an example this time:\n```php\n/** @var Notice $notice */\n$notice = model(NoticeModel::class)-\u003efirst();\nsession('notice', $notice);\n...\n\n// Later that same day...\nalert('notice', 'Site statistics are currently being updated, expect longer load times.');\n```\n\nWe have just tried to set an alert for a Session key that already exists and contains\nsomething that is not another alert! There are a few ways that this can play out, but\nultimately this was a mistake and you should take care to avoid it.\n\nTo clarify the example:\n1. `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);`.\n2. 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.\n3. Setting Session keys yourself is a fine solution, but you must handle checks for existing keys or risk overwriting data.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftattersoftware%2Fcodeigniter4-alerts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftattersoftware%2Fcodeigniter4-alerts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftattersoftware%2Fcodeigniter4-alerts/lists"}