ianikanov/yii2-wce

Ability to generate widgets with interface similar to controller with basic CRUD actions for specific model

Installs: 1 234

Dependents: 0

Suggesters: 0

Security: 0

Stars: 5

Watchers: 2

Forks: 1

Open Issues: 0

Type:yii2-extension

0.3 2020-03-08 17:46 UTC

This package is auto-updated.

Last update: 2024-12-15 21:20:53 UTC


README

Ability to generate widgets with interface similar to controller with basic CRUD actions for specific model

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist ianikanov/yii2-wce "dev-master"

or add

"ianikanov/yii2-wce": "dev-master"

to the require section of your composer.json file.

Usage

Once the extension is installed, add new template to your config file :

if (YII_ENV_DEV) {    
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',      
        'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '192.168.178.20'],  
        'generators' => [ //here
            'widgetCrud' => [
                'class' => '\ianikanov\wce\templates\crud\Generator',
                'templates' => [
                    'WCE' => '@vendor/ianikanov/yii2-wce/templates/crud/default', // template name
                ],
            ],
        ],
    ];
}

And register embedded controller:

$config = [
    ...
    'controllerMap' => [
        'wce-embed' => '\ianikanov\wce\Controller',
    ],
    ...
];

Then run gii, select "CRUD Controller Widget" fill the form and generate the code.

To use widget in any other form follow examples below.

To show list of items, for example, the list of Posts related to the current model:

<?= app\widgets\PostControllerWidget::widget([
    'action' => 'index',
    'params' => [
        'query' => $model->getPosts(),
    ],
]) ?>

To show a single item details, for example the post

<?= app\widgets\PostControllerWidget::widget([
    'action' => 'view',
    'params' => [
        'id' => $post_id,
    ],
]) ?>

To show create button with modal window:

<?= app\widgets\PostControllerWidget::widget(['action' => 'create']) ?>

To show update button with modal window:

<?= app\widgets\PostControllerWidget::widget(['action' => 'update', 'params'=>['id' => $model->id]]) ?>

To show delete button:

<?= app\widgets\PostControllerWidget::widget(['action' => 'delete', 'params'=>['id' => $model->id]]) ?>