1. Go to this page and download the library: Download rafaelwendel/ci4alerts library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// Instantiates using the default framework defined in the active property of app/Config/Alerts.php
$alerts = service('alerts');
// Instantiates forcing a specific framework override
$alertsBootstrap = service('alerts', 'bootstrap');
namespace App\Controllers;
class Products extends BaseController
{
public function save()
{
// ... saving logic ...
// Set a success alert
service('alerts')->set('Product registered successfully!', 'success');
// Or set an error alert
service('alerts')->set('Could not save the product.', 'error');
return redirect()->to('/products');
}
}
<?= service('alerts')->display()
<?= service('alerts')->display('This is a direct message!', 'warning')