2017 © Pedro Peláez
 

yii2-extension yii2-modal

Yii2 Bootstrap Modal wrapper

image

tunect/yii2-modal

Yii2 Bootstrap Modal wrapper

  • Sunday, October 8, 2017
  • by dvatri
  • Repository
  • 1 Watchers
  • 0 Stars
  • 11 Installations
  • JavaScript
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Bootstrap Modal wrapper for Yii2 framework

This module provides modal pop-over window for controller actions., (*1)

Installation

Run CLI command to install extension:, (*2)

composer require tunect/yii2-modal

That's it, module will work. Additional settings are optional., (*3)

Optional settings

To specify custom module name (default name is modal) set it in index.php or in config file (before config goes to Application constructor):, (*4)

\tunect\Yii2Modal\Module::$moduleName = 'custom-modal';

Module settings can be changed in app config:, (*5)

'modules' => [
    'modal' => [
        'class' => 'tunect\Yii2Modal\Module',
    ],
],

Usage

To let some page be rendered in modal add widget to layout (e.g. right before $this->endBody()):, (*6)

<?= \tunect\Yii2Modal\Widget::widget() ?>

Widged should be added only once since it uses an id attribute (hence expected to be unique). Widged just adds basic empty elements to be filled and displayed on demand., (*7)

And add a link (a tag) or any other element with showModalButton class:, (*8)

<?= Html::a('Add product', ['/product/create'], ['class' => 'btn btn-primary showModalButton']) ?>

href attribute will be used for a elements to get Ajax request URL, value attribute for all other elements (tags)., (*9)

E.g. <a href="/some-url" class="showModalButton">Get modal</a> is equal with <button value="/some-url" class="showModalButton">Get modal</button>, some-url response will be used to fill modal in both cases., (*10)

To handle Ajax requests and render response in modal use JSON format:, (*11)

if (Yii::$app->request->isAjax) {
    Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
    return [
        'status' => 200,
        'message' => $message, // Any html to be displayed in modal (e.g. yii\web\Controller::renderAjax() method output)
        'pjax' => "#products-list", // To reload pjax container with id "products-list" (e.g. grid after element creation in modal)
    ];
}

The Versions

08/10 2017

dev-master

9999999-dev

Yii2 Bootstrap Modal wrapper

  Sources   Download

BSD-3-Clause

The Requires

 

by Tunect

08/10 2017

1.0.1

1.0.1.0

Yii2 Bootstrap Modal wrapper

  Sources   Download

BSD-3-Clause

The Requires

 

by Tunect

08/08 2017

1.0.0

1.0.0.0

Yii2 Bootstrap Modal wrapper

  Sources   Download

BSD-3-Clause

The Requires

 

by Tunect