relbraun/yii2repeater

yii2表格的Repeater小部件

安装数: 4,808

依赖项: 0

建议者: 0

安全性: 0

星标: 11

关注者: 5

分支: 3

开放性问题: 0

类型:yii2-extension

1.0.1 2017-08-20 07:26 UTC

This package is not auto-updated.

Last update: 2024-09-14 20:14:53 UTC


README

一个Yii2小部件,使您能够以简单的方式实现 Yii2表格

##如何使用

使用Composer安装: composer require relbraun/yii2repeater

将此代码放入您的表单中

<?php echo Repeater::widget([
        'modelView' => '@backend/views/path/to/your/repeater_view_file',
        'appendAction' => \yii\helpers\Url::to(['add-item-action']),
        'removeAction' => \yii\helpers\Url::to(['remove-item-action']),
        'form' => $form,
        'models' => $models, //The existing sub models
    ]) ?>

在您希望使用此小部件的控制器中放入此代码

public function actions()
    {
        return [
            'add-item' => [
                'class' => 'relbraun\yii2repeater\actions\AppendAction',
                'model' => 'backend\models\DesiredModel',
                'contentPath' => '/path/to/repeater/view', //related to current controller
            ],
            'remove-item' => [
                'class' => 'relbraun\yii2repeater\actions\DeleteAction',
                'model' => 'backend\models\DesiredModel',
            ]
        ];
    }

以上是上述repeater_view_file.php示例的代码

<div class="repeater-content">
    <div class="form-group">
        <?= Html::label('Some label', Html::getInputId($model, "[$k]attribute")) ?>
        <?= Html::activeTextInput($model, "[$k]attribute", ['class' => 'form-control']) ?>
    </div>
    <div class="form-group">
        <?= Html::label('Other label', Html::getInputId($model, "[$k]other_attribute")) ?>
        <?= Html::activeTextInput($model, "[$k]other_attribute", ['class' => 'form-control']) ?>
    </div>
</div>