PHP code example of rft / yii2-alert-modal-widget

1. Go to this page and download the library: Download rft/yii2-alert-modal-widget 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/ */

    

rft / yii2-alert-modal-widget example snippets


<?= \frontend\components\widgets\AlertModalWidget::widget([
    'triggerSelector' => '.modal-delete-trigger',
    'title' => 'Delete Confirmation',
    'body' => 'This item will be deleted permanently.',
    'iconType' => 'warning',
    'iconColor' => '#f8bb86',
    'confirmButtonLabel' => 'Delete',
    'confirmButtonClass' => 'alert-modal-btn-confirm btn-danger', // Base class + color class
]) 

<?= Html::a('<i class="fa fa-eye"></i> View', ['/item/view', 'id' => 1], [
    'class' => 'btn btn-info modal-view-trigger', // Your button styles + trigger class
    'data' => [
        'alert-modal-title' => 'View Item Details',
        'alert-modal-body' => 'Are you sure you want to view this item?',
        'alert-modal-confirm-label' => 'Yes, View Details',
    ],
]) 

<!-- 1. Define your modals -->
<?= \frontend\components\widgets\AlertModalWidget::widget([
    'triggerSelector' => '.modal-delete-trigger',
    'title' => 'Delete Confirmation',
    'confirmButtonLabel' => 'Delete',
    'confirmButtonClass' => 'alert-modal-btn-confirm btn-danger', // REQUIRED FORMAT
    'iconType' => 'warning',
    'iconColor' => '#f8bb86',
]) 

<!-- Modal Widgets -->
<?= \frontend\components\widgets\AlertModalWidget::widget([
    'triggerSelector' => '.modal-delete-trigger',
    'title' => 'Delete Confirmation',
    'confirmButtonLabel' => 'Delete',
    'confirmButtonClass' => 'alert-modal-btn-confirm btn-danger',
    'iconType' => 'warning',
    'iconColor' => '#f8bb86',
]) 

'confirmButtonClass' => 'alert-modal-btn-confirm btn-danger' // Base class + color class

   // ✅ Correct:
   'confirmButtonClass' => 'alert-modal-btn-confirm btn-danger'

   // ❌ Wrong (will break styling):
   'confirmButtonClass' => 'btn btn-danger'
   

   // Your trigger buttons use normal Bootstrap classes:
   'class' => 'btn bg-gradient-danger btn-xs modal-delete-trigger'
   // The modal trigger class is just added to the end
   

   <?= Html::csrfMetaTags()