Download the PHP package rafaelwendel/ci4alerts without Composer
On this page you can find all versions of the php package rafaelwendel/ci4alerts. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rafaelwendel/ci4alerts
More information about rafaelwendel/ci4alerts
Files in rafaelwendel/ci4alerts
Package ci4alerts
Short Description A helper to display message alerts in CodeIgniter 4 framework.
License MIT
Homepage https://github.com/rafaelwendel/CI4Alerts
Informations about the package ci4alerts
CI4Alerts
CI4Alerts is a helper library for the CodeIgniter 4 framework designed to simplify the creation, management, and display of message alerts (such as success, error, and warning messages) using the most popular CSS frameworks: Bulma, Bootstrap, Materialize, and Tailwind CSS.
Installation
The package can be easily installed via Composer. Run the following command in your terminal at the root of your CodeIgniter 4 project:
Configuration
Setup Command (Spark)
After installing the library, you should publish the package's default configuration template file to your application's Config directory (app/Config). To do this, run the Spark command below in your terminal:
This command will copy the configuration template file to app/Config/Alerts.php.
Configuration Options
When you open app/Config/Alerts.php, you will find the following configuration options:
$active: Defines the default styling library that will be used by the service. The supported options are:'bulma'(Default)'bootstrap''materialize''tailwind'
$config: Contains framework-specific styling and behavior sub-arrays for each supported CSS framework. The options inside each framework sub-array are:classSucess: CSS class applied to success alerts.classError: CSS class applied to error/danger alerts.classWarning: CSS class applied to attention/warning alerts.sessionMsg: Session key name (flashdata) used to store the message text.sessionMsgType: Session key name (flashdata) used to store the message type.template: HTML template where the CSS class and message will be injected. Supports PHP formatting placeholders (%s) or replacement tags ({class}and{message}).
Adding Custom Configurations
If you do not want to use any of the built-in libraries, you can easily define your own custom configurations by adding new keys to the $config array. To use a custom configuration, simply set the $active property to your custom key:
You can then load your custom theme automatically:
Or load it explicitly by passing its key as an argument:
Usage Examples
1. Obtaining the Service Instance
The recommended way to instantiate the library is using CodeIgniter 4's service() helper:
2. Setting Alert Messages (Controller)
You can store alert messages in session flashdata to display them after a redirect (e.g., after saving a form):
3. Displaying Alert Messages (Views)
Automatic Session (Flashdata) Display
To display the alert set in the controller, simply call the display() method in your view:
Direct Display (Without Session / Static Rendering)
If you prefer to render a message directly in the view, pass the parameters to the display() method:
Shortcut Helper Methods
You can also use type-specific shortcut methods directly in the view: