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.