conquer / gii-modal
Gii CRUD generator for Yii2 with view, create and update pages in a Bootstrap 3/4/5 modal
Requires
- php: ^7.4 || ^8.0
- yiisoft/yii2: ~2.0.14
- yiisoft/yii2-gii: ~2.0
Requires (Dev)
None
Suggests
- yiisoft/yii2-bootstrap: Bootstrap 3 modal
- yiisoft/yii2-bootstrap4: Bootstrap 4 modal
- yiisoft/yii2-bootstrap5: Bootstrap 5 modal (one of the Yii Bootstrap extensions is required)
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-07 02:04:32 UTC
README
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-bootstrap4oryiisoft/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
GiiAssetno longer registers Bootstrap 3 (yii\bootstrap\BootstrapAsset,BootstrapPluginAsset): Bootstrap is registered by theModalwidget and by your layout. Code generated by older versions keeps working withyiisoft/yii2-bootstrapinstalled.- 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.