PHP code example of rafaelwendel / ci4alerts

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/ */

    

rafaelwendel / ci4alerts example snippets


public $active = 'my_custom_theme';

public $config = [
    // ...
    'my_custom_theme' => [
        'classSucess'    => 'my-custom-success-class',
        'classError'     => 'my-custom-danger-class',
        'classWarning'   => 'my-custom-warning-class',
        'sessionMsg'     => 'msg',
        'sessionMsgType' => 'msg_type',
        'template'       => '<div class="%s">%s</div>',
    ],
];

$alerts = service('alerts'); // Uses 'my_custom_theme'

$alerts = service('alerts', 'my_custom_theme');

// 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') 

// Success Alert
<?= service('alerts')->success('Operation completed successfully!') 
bash
php spark alerts:setup