Search by

conquer / gii-modal

borodulin

Gii CRUD generator for Yii2 with view, create and update pages in a Bootstrap 3/4/5 modal

Package info

github.com/borodulin/yii2-gii-modal

Type:yii2-extension

pkg:composer/conquer/gii-modal

Statistics

Installs: 14 295

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

1.3.0 2026-11-07 01:53 UTC

This package is auto-updated.

Last update: 2026-11-07 02:04:32 UTC


README

Latest Version Total Downloads License

Description

A Gii CRUD generator whose controller and views open the view, create and update pages in a Bootstrap modal on the index page:

  • the page is loaded into the modal via AJAX, forms are submitted via AJAX (file uploads included);
  • validation errors are shown in the modal, after a successful save the index page is reloaded;
  • pages opened directly (without the modal) keep working as usual;
  • Bootstrap 3, 4 and 5 are supported.

Requirements

  • PHP 7.4 or 8.x
  • Yii 2.0.14 or newer (2.0.x) with yii2-gii
  • one of the Yii Bootstrap extensions: yiisoft/yii2-bootstrap5, yiisoft/yii2-bootstrap4 or yiisoft/yii2-bootstrap (Bootstrap 3)

Installation

Install the extension via Composer:

composer require conquer/gii-modal:^1.3

Install it as a regular dependency, not with --dev: the generated code uses conquer\gii\GiiAsset and conquer\gii\ModalActionColumn at runtime.

Usage

Register the generator in the Gii module configuration:

if (YII_ENV_DEV) {
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        'allowedIPs' => ['127.0.0.1', '::1'],
        'generators' => [
            'modal_crud' => [ // generator name
                'class' => 'conquer\gii\templates\crud\Generator',
            ],
        ],
    ];
}

Open Gii, choose Modal CRUD Generator and fill the form as for the standard CRUD generator, or use the console:

php yii gii/modal_crud --modelClass='app\models\Post' --searchModelClass='app\models\PostSearch' \
    --controllerClass='app\controllers\PostController'

Bootstrap version

Bootstrap Version (--bsVersion) defaults to the newest installed Yii Bootstrap extension. Set it explicitly when several are installed. The generated index page uses the Modal widget of that extension; Bootstrap CSS is included by your layout, as usual.

Modal buttons in your own grids

conquer\gii\ModalActionColumn is a regular ActionColumn whose view and update buttons open in the modal (the icons and other options of the default buttons are kept):

use conquer\gii\GiiAsset;
use conquer\gii\ModalActionColumn;
use yii\bootstrap5\Modal;

GiiAsset::register($this);

echo Modal::widget(['id' => 'modal_view', 'title' => '']);

echo GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => [
        'id',
        'title',
        [
            'class' => ModalActionColumn::class,
            'modalTarget' => '#modal_view',
            'modalHeaders' => ['view' => 'View Post', 'update' => 'Update Post'],
        ],
    ],
]);

Any link can open a page in the modal:

echo Html::a('Create Post', ['create'], [
    'class' => 'show-modal',
    'data-target' => '#modal_view',
    'data-header' => 'Create Post', // plain text
]);

Forms with the data-ajax attribute inside the modal are submitted via AJAX.

Upgrading to 1.3

  • GiiAsset no longer registers Bootstrap 3 (yii\bootstrap\BootstrapAsset, BootstrapPluginAsset): Bootstrap is registered by the Modal widget and by your layout. Code generated by older versions keeps working with yiisoft/yii2-bootstrap installed.
  • Re-generate the views to get Bootstrap 4/5 support and ModalActionColumn.

License

conquer/gii-modal is released under the MIT License. See the bundled LICENSE for details.