Tabular Input Doesnot Work

i create a tabular input base on this example => http://www.yiiframework.com/doc/guide/1.1/en/form.table. but i still could not make it work. my progress so far :

controller





<?php

	public function actionAddNew($id)

	{

			$model=new StudentSubjectDetail;

            $studentsubject = StudentSubject::model()->findByAttributes(array('student_subject_id'=>$id));

            $subjectschedules = SubjectSchedule::model()->findAllByAttributes(array('period_id'=>$studentsubject->period_id));

            // Uncomment the following line if AJAX validation is needed

            // $this->performAjaxValidation($model);

            if(isset($_POST['SubjectSchedule'])){

                foreach ($subjectschedules as $subject) {

                    /*

                     * LINE BERIKUT ERROR : Illegal offset type in isset or empty

                     */

                    if (isset($_POST['SubjectSchedule'][$subject])) {


                        $tmpSubjectSchedule = new SubjectSchedule;

                        $tmpSubjectSchedule->attributes=$_POST['SubjectSchedule'][$subject];

                        $OK=$tmpSubjectSchedule->check;

                        $TOK=$tmpSubjectSchedule->staff_id;

                        if($tmpSubjectSchedule->check==1){

                            $model->student_subject_id = $id;

                            $model->subject_id = $tmpSubjectSchedule->subject_id;

                            $model->staff_id = $tmpSubjectSchedule->staff_id;

                            $model->description = $tmpSubjectSchedule->check;

                            $model->save();

                        }                            


                    }

                }


                $this->redirect(array('view','id'=>$model->student_subject_detail_id));

            }


            $this->render('addnew',array(

                'model'=>$model,

                'studentsubject'=>$studentsubject,

                'subjectschedules'=>$subjectschedules

            ));

	}	

?>

[size=2]

[/size]

_form.php




	<?php $form=$this->beginWidget('bootstrap.widgets.BsActiveForm', array(

		'id'=>'student-subject-detail-form',

		// Please note: When you enable ajax validation, make sure the corresponding

		// controller action is handling ajax validation correctly.

		// There is a call to performAjaxValidation() commented in generated controller code.

		// See class documentation of CActiveForm for details on this.

		'enableAjaxValidation'=>false,

		'htmlOptions'=>array('enctype'=>'multipart/form-data')

	)); ?>


		<div class="alert alert-success">

			Subject offered

		</div>


		<table class="table table-condensed">    

			<tr>

				<th>Class Room</th><th>Subject</th><th>Teacher</th>

				<th>Weekday</th><th>Time</th><th>Check</th>

			</tr>    

			

			<?php

				foreach($subjectschedules as $subject) {    

			?>

					<tr>

					  <td><?php echo $subject->classRoom->class_room_name;?></td>

					  <td><?php echo $subject->subject->subject_name;?></td>

					  <td><?php echo $subject->staff->staff_name;?></td>

					  <td><?php echo Yii::app()->locale->getWeekDayName($subject->week_day);?></td>       

					  <td><?php echo $subject->time_start.' - '.$subject->time_end ;?></td>

					  <td><?php echo $form->checkBox($subject,'[$subject]check');?></td>

					</tr>

			<?php

				}

			?>    

		</table>    

		<br></br>

		<?php echo BsHtml::submitButton('Submit', array('color' => BsHtml::BUTTON_COLOR_PRIMARY)); ?>


	<?php $this->endWidget(); ?>



please help if any of you know, why the code does not work. thank you. :)

The example use the $i variable (array key) not the array value in the foreach:




foreach($items as --->$i<--- =>$item)

{

    if(isset($_POST['Item'][--->$i<---]))

        $item->attributes=$_POST['Item'][--->$i<---];

    $valid=$item->validate() && $valid;

}


// ....


<?php foreach($items as --->$i<--- =>$item): ?>

<tr>

<td><?php echo CHtml::activeTextField($item,"[--->$i<---]name"); ?></td>

<td><?php echo CHtml::activeTextField($item,"[--->$i<---]price"); ?></td>

<td><?php echo CHtml::activeTextField($item,"[--->$i<---]count"); ?></td>

<td><?php echo CHtml::activeTextArea($item,"[--->$i<---]description"); ?></td>

</tr>

<?php endforeach; ?>



try this:




foreach ($subjectschedules as $i => $subject) {

    if (isset($_POST['SubjectSchedule'][$i])) {

        // .......

        $tmpSubjectSchedule->attributes=$_POST['SubjectSchedule'][$i];

        // .......

    }

}






<?php

foreach($subjectschedules as $i => $subject) {  

?>

    <tr>

        .....

        <td><?php echo $form->checkBox($subject,"[$i]check");?></td>

    </tr>

<?php

}

?>



thanx mate, it works now :D