Tabular Input For Multiple CListViews

I have an array of dataproviders that I loop through and provide to the CListView widget. All of this data comes from one model/table (but many instances of the model). I wrap all these CListView widgets in one form. Each table data is an input field with the associated data. Of course when I post the data I only get the first record.

I’ve read through this: but I can’t make it work with this situation.

My question: How would I retrieve and update this data in a batch? I will be eternally grateful for any help!! I’ve been beating my head for days on this.

Below is my code:

The View:

    <?php echo CHtml::beginForm(); ?>

        <?php foreach ($dataProvider as $data): ?>



                $data->pagination->pageSize = $data->totalItemCount;

                $this->widget('zii.widgets.CListView', array(

                    'dataProvider'     => $data,

                    'enablePagination' => FALSE,

                    'itemView'         => '_tableView',

                    'template'         => '{items}',





        <?php endforeach; ?>

    <?php echo CHTML::button('Update'); ?>

  <?php echo CHtml::endForm(); ?>

CListView View:


    <td><?php echo $data->account; ?></td>

    <td><?php echo CHtml::TextField('description', $data->description); ?></td>

    <td><?php echo CHtml::TextField('july', $data->july, 2); ?></td>

    <td><?php echo CHtml::TextField('august', $data->august, 2); ?></td>

    <td><?php echo CHtml::TextField('september', $data->september, 2); ?></td>


Just a quick thought: Maybe you could wrap with a dynamic <fieldset name="$data->???"> tag somehow and maybe that would give you an array to loop through in the saving routine.

I’ll have to give a try and report back.

I would like to ask what the ‘2’ at the end of the CHtml::textField() calls is? The docs say it is supposed to be an array().

I apologize for my late response. The 2 was a simple copy & paste mistake. I’ve fixed the problem with code that looks like the following:

<?php echo CHtml::beginForm(); ?>

<?php foreach ($query as $i => $data): ?>       

 <table id="<?php echo $i; ?>">           

    <?php foreach ($data as $row): ?>


                <td><?php echo $row->account; ?></td>

                <td><?php echo CHtml::activeTextField($row, "[$row->id]description"); ?></td>

                <td><?php echo CHtml::activeTextField($row, "[$row->id]july"); ?></td>

                <td><?php echo CHtml::activeTextField($row, "[$row->id]august"); ?></td>

                <td><?php echo CHtml::activeTextField($row, "[$row->id]september"); ?></td>


    <?php endforeach; ?>



                <td><input type="text" name="New[<?php echo $i; ?>][description]"></td>

                <td><input type="text" name="New[<?php echo $i; ?>][july]"></td>

                <td><input type="text" name="New[<?php echo $i; ?>][august]"></td>

                <td><input type="text" name="New[<?php echo $i; ?>][september]"></td>



<?php endforeach; ?>

<?php echo CHTML::button('Update', array('submit' => Yii::app()->createUrl("budget/updateRecords"))); ?>

<?php echo CHtml::endForm(); ?>

I wasn’t able to get it to work with the CListView. Instead I loop through the array of instances of the model, then I loop through each record set. I also add a blank row of inputs at the end of each table. Hope it can help someone in the future.