0

我正在尝试想出一种更新模型的多条记录的方法,并且当我使用 YiiBooster 时,我已经看到您可以使用扩展网格进行批量操作。

我在网上找到的大多数示例都展示了如何使用 Ajax 删除多条记录,但我的要求略有不同。作为 Yii 的新手,我正在努力寻找合适的解决方案。

基本上我有 2 个模型,一个父级和一个具有一对多关系的子级。在子模型中,我有一个字段,它使用父 ID 引用它属于哪个父。

在应用程序的前端,用户应该导航到父更新视图,然后查看分配给该父的所有子的列表。我创建了一个模式窗口,它显示了所有具有执行批量更新操作能力的子项的网格列表。然后,这会将父 ID 分配给所有选择的子代。

谁能帮我解决这个问题,因为我不确定我需要在扩展网格视图和控制器中编辑什么来更新记录?

在我的父更新视图中,我使用 renderPartial 拉入子项的索引视图,如下所示:

<?php $this->renderPartial('application.modules.children.views.childviews.addChild', array('dataProvider' => new CActiveDataProvider('Children'))); ?>

然后,我的子索引视图中有一个扩展网格:

<?php
$this->widget('bootstrap.widgets.TbExtendedGridView', array(
    'type' => 'striped bordered',
    'id' => 'children-grid',
    'dataProvider' => $dataProvider,
    'bulkActions' => array(
        'actionButtons' => array(
            array(
                'buttonType' => 'link',
                'type' => 'primary',
                'size' => 'small',
                'label' => 'Bulk Action',
                'url' => array('batchUpdate'),
                'htmlOptions' => array(
                    'class' => 'bulk-action'
                ),
                'id' => 'child_id',
                'click' => ''
            )
        ),
        'checkBoxColumnConfig' => array(
            'name' => 'child_id'
        ),
    ),
    'columns' => array(
        'child_id',
        'child_status',
        'parent_id',
        array(
            'class' => 'bootstrap.widgets.TbButtonColumn',
            'buttons' => array(
                'update' => array(
                    'label' => '<i class="icon-user"></i> <span>View Child</span>',
                    'options' => array('class' => 'btn btn-small'),
                    'url' => 'Yii::app()->createUrl("children/update", array("id"=>$data->child_id))',
                ),
            ),
        ),
    ),
));
?>

我猜我需要某种 onclick 事件来调用控制器中的更新操作,并且此操作将所有选定记录的 parent_id 列更新为当前父更新页面的父 ID?

我希望有人可以提供帮助,并提前非常感谢。

4

1 回答 1

0

Instead of a one to many relationship as you stated in your question, it seams that you really want a many to many relationship. The reason I say that is you seem to want to select from a set of pre-defined properties for your auction. In that case you would display the parent (auction), and the list of perspective children (properties), and using a checkbox or something like that to indicate the selection of the perspective children. You will have to use a separate data model to record the selections. I don't have an example right now, but I will need to do something like this in my current Yii project, and I will blog about it when I get there.

于 2013-06-18T01:44:21.057 回答